I have a file that looks like this:
namespace myName
{
typedef HRESULT (*PFN_HANDLE)(myName::myStruct);
class MyClass{
//...
public:
BOOL RegisterCallback (PFN_HANDLE foo);
//...
};
struct myStruct{
//...
};
}
But I am getting a compile error 'myStruct' is not a member of 'myName'. Can anyone tell me what is going on? It's okay to declare a struct in my header file, right? Is it a namespace issue? I'm sorry to be so dense.
From stackoverflow
-
You are trying to use the type name myStruct before you have declared it. Either put the whole struct definition before the typedef, or put this declaration before the typedef:
struct myStruct;This is known as a "forward declaration". It tells the compiler that there will later be a type with that name, but doesn't say exactly how that type is defined.
John Nolan : reminds me of my delphi dayssheepsimulator : @ Malcolm - Almost everyone that starts out writing C++ gets bitten by forward declaration issues at some point.
0 comments:
Post a Comment