【问题标题】:Was not declared in this scope with Friendly Function未在此范围内使用友好函数声明
【发布时间】:2012-05-21 23:18:30
【问题描述】:

我不确定为什么会发生这种情况,但似乎它错误地抛出了“未在此范围内声明”错误。我这样说是因为它适用于我的 Windows 计算机(MSVC 编译器),但它不适用于我的 Mac(GCC)。我正在使用 Qt Creator 来编写这个。这是我的情况:

它在我的 pushButtonClicked 上引发错误...

void NewGpdDialog::on_pushButton_clicked()
{
    *xdbf = XDBFcreate(filePath.toStdString(), Achievement, ba.data(), ba.size(), &str);
}

它抛出的确切错误是:

.../newgpddialog.cpp:63: 错误:'XDBFcreate' 未在此范围内声明

我几乎肯定它已被标定,因为在我的文件顶部我包括:

#include "newgpddialog.h"
#include "ui_newgpddialog.h"
#include "xdbf.h"
#include <QDesktopServices>
#include <QBuffer>
#include <QFileDialog>
#include <QMessageBox>

“xdbf.h”是它的声明位置...这是我的 XDBF 头文件的一部分:

class XDBF
{
public:
    XDBF(string path);
    ~XDBF();

    ...

    static std::string FILETIME_to_string(FILETIME *pft);
    friend XDBF* XDBFcreate(string filePath, GPD_Type type, char *imageData = NULL, size_t imageDataLen = 0, wstring *gameName = NULL);

我现在将它放在我的“xdbf.cpp”文件中,如下所示:

XDBF* XDBFcreate(string filePath, GPD_Type type, char *imageData, size_t imageDataLen, wstring *gameName)
{
    ...
}

另外,有趣的是,如果我在标题中右键单击它,然后单击“跟随光标下的符号”,它找不到它...另一件事是,请记住,这适用于我的 Windows电脑。

【问题讨论】:

  • 除非我弄错了XDBFcreate 似乎不是静态方法。

标签: c++ qt function declare


【解决方案1】:

友元声明不作为完整的函数声明。

您需要为 XDBFcreate 单独声明。

【讨论】:

    【解决方案2】:

    仅声明为友元的函数,未使用单独的命名空间范围声明进行声明,只能通过 Argument-Dependent Lookup 找到。您对XDBFcreate 的调用不涉及XDBF 类型的参数,因此在该类中声明的友元函数无法通过名称查找找到。

    要修复代码,请在 XDBF 的声明之前添加 XDBFcreate 的命名空间范围声明

    【讨论】:

      猜你喜欢
      • 2020-08-23
      • 2015-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多