Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Neutral Gamer

macrumors 6502a
Original poster
Hi guys, I'm porting over some C++ code that I wrote for Windows where it works fine (Visual C++) but in Mac OS X I'm getting errors. Here's the problem:

Let's say I've got a simple base class as follows:

Code:
template <typename T>
struct BaseClass
{
    typedef void (*HandlerType) (int);
};

And then a derived class as follows:

Code:
template <typename T>
struct DerivedClass : public BaseClass<T>
{
    void Testground (HandlerType Handler)
    {
    }
};

When trying to compile I get an error that says "HandlerType has not been declared". I also tried using the fully qualified name for the HandlerType:

Code:
struct DerivedClass : public BaseClass<T>
{
    void Testground (BaseClass<T>::HandlerType Handler)
   {
   }
};

But then I get the error: "struct BaseClass<T>::HandlerType is not a type". If I don't make the classes templates then it works fine. I'm sure there's a really simple solution to this problem that's staring me in the face but I'm new to Mac / GCC programming so any help would be much appreciated!

Cheers. :)
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
gcc is stricter and usually more correct than Microsoft compilers. So you don't have a Mac/gcc problem, you have a C++ problem.

HandlerType is not based on the template, that is most likely the cause of the problem. That and some bizarre rules about instantiating templated stuff that gcc implements closer to the C++ Standard than others.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.