tags:

views:

83

answers:

1

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.

+6  A: 

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.

Tyler McHenry
reminds me of my delphi days
John Nolan
@ Malcolm - Almost everyone that starts out writing C++ gets bitten by forward declaration issues at some point.
sheepsimulator