0

I'm sorry for asking so much, but I've encountered another problem I have no idea how to solve... From what I gather, gcc fails to resolve myComparator class type, probably because the following code is not compliant with the standard. The question is if I am missing something or is there a workaround for this problem, which wouldn't require too much changes (like interfaces solution)...

template <typename DATA> class myArray
{
    template <typename F> void sort (F &comp)
    {
        // No problems here
    }

    template <typename T> void sort(void)
    {
        T::myComparator cmp; //Error: expected `;' before 'zzz'
        // T::template myComparator cmp; also doesn't work
        sort(cmp);
    }
};

class test
{
public:
    class myComparator
    {
    public:
        bool operator() ( const test *t1, const test * t2)
        {
            // No problems here
        }
    };
};

void testCmp()
{
    myComparator cmp;
    cmp.sort<test>();
}
Ryan
  • 1,451
  • 2
  • 27
  • 36

1 Answers1

1

You've to use typename as:

  typename T::myComparator cmp; 
//^^^^^^^

typename is required because myComparator is a dependent name.

See this C++ FAQ at stackoverflow itself:

"Where and why do I have to put template and typename on dependent names?"

Community
  • 1
  • 1
Nawaz
  • 353,942
  • 115
  • 666
  • 851
  • 1
    This is a ***fcking annoying*** point about MSVC. It does not implement proper name lookup, and is very laxist about the `typename` and `template` keyword on dependent names. This causes portability nightmares, and there is no compiler option to show a warning on this point. – Alexandre C. May 12 '11 at 06:34