views:

164

answers:

1

My C++-fu isn't very good and I can't seem to figure out this issue.

I have a header file with a typedef in a couple namespaces like so:

namespace gui {
   namespace output {
      typedef Collections::Generic::List<int> MyTypeDef;
   }
}

In a cpp file which includes that header file I have the following code:

array<gui::output::MyTypeDef^> ^ SomeFunction(int Param)
{
   // ... yada yada ...
}

I keep getting the compile error:

'MyTypeDef' : is not a member of 'gui::output'.

I'm really confused because intellisense certainly picks up on it... help?

A: 

Sometimes error messages like this can be rather misleading and point you in the wrong direction. (i.e. Is your type not declared in the namespace, or does the compiler just not recognise the namespace at all, or is it confused by something wrong in the syntax near the code it is complaining about?)

A couple of temporary simplifications will help you narrow down the problem until you discover the root cause. Once you understand it, you can rework the code into a tidier form again. Try these options:

  • Check that the header is being included and working ok - a good start is to try the typedef in the cpp file just above where you're using it. If it works there but not in the header, then your header's not being included, or the typedef is being conditionally compiled away (etc).
  • See if it works in a simpler case: Use a basic "MyTypeDef a;" to confirm that it's not just a syntax error in your usage.
  • See if it works better without the namespaces.

Eliminate all the things that aren't causing a problem and what you'll be left with is the cause.

Jason Williams
I moved the typedefs into the cpp file temporarily and I was able to get it to compile. However the header file is being included because another class from that same header file is being instantiated and I don't get any compile errors there. It's just the typedefs that seem to have an issue.
Spencer Ruport
Try moving the typedefs to the top of the header file - perhaps something part way down the header is interfering with them? (the obvious one is that somewhere above the typedefs you have entered an "#if" block that is disabling the typedefs, but sometimes a glitch in code may not trigger an error immediately that it happens, and will show up as a "weird problem" in a later piece of code).
Jason Williams