Question

I am not sure why this is happening, but it seems like it is throwing a "was not declared in this scope" error, falsely. I say this because it works on my Windows computer (MSVC compiler), but it will not work on my Mac (GCC). I am using Qt Creator to write this. Here is my situation:

It throws the error on my pushButtonClicked...

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

the exact error it throws is:

.../newgpddialog.cpp:63: error: 'XDBFcreate' was not declared in this scope

I am almost positive it is decalared, because at the top of my file I include:

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

"xdbf.h" is where it is declared... Here is part of my XDBF header file:

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);

I now have it in my "xdbf.cpp" file like this:

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

Also, and interesting thing is that if I right click it in the header, and click "Follow Symbol Under Cursor", it cannot find it... Another thing is, keep in it in mind that this works on my Windows computer.

Was it helpful?

Solution

Friend declarations don't act as a full function declaration.

You need to have a separate declaration for XDBFcreate.

OTHER TIPS

A function which is only declared as a friend, not also declared with a separate namespace-scope declaration, is only findable by Argument-Dependent Lookup. Your call to XDBFcreate does not involve an argument of type XDBF so the friend function declared in that class is not found by name lookup.

To fix the code add a namespace-scope declaration of XDBFcreate before the declaration of XDBF

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top