简体   繁体   中英

Namespace class and struct

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM