3

I'm trying to port a project from Windows to Mac. I'm having troubles compiling the class CFactory. I'll try to illustrate the problem.

Here's what I have on my Factory.h

namespace BaseSubsystems
{
    template <class T>
    class CFactory
    {
    protected:
        typedef T (*FunctionPointer)();
        typedef std::pair<std::string,FunctionPointer> TStringFunctionPointerPair;
        typedef std::map<std::string,FunctionPointer> TFunctionPointerMap;
        TFunctionPointerMap _table;
    public:
        CFactory () {}
        virtual ~CFactory();
    }; // class CFactory

    template <class T> 
    inline CFactory<T>::~CFactory()
    {
        TFunctionPointerMap::const_iterator it = _table.begin();
        TFunctionPointerMap::const_iterator it2;

        while( it != _table.end() )
        {
            it2 = it;
            it++;
            _table.erase(it2);
        }

    } // ~CFactory
}

When I'm trying to compile, the compiler complains:

Factory.h:95:44: error: expected ';' after expression [1]
         TFunctionPointerMap::const_iterator it = _table.begin();
                                            ^
                                            ;

Why is this happening? That am I missing?

NOTE: This project compiles properly on MSVC.

Thanks.

frarees
  • 2,190
  • 3
  • 17
  • 22

1 Answers1

4

You are missing the required typename keyword when referring to a dependent type. Microsoft Visual Studio incorrectly accepts your code without the typename (this is a well known mistake in VS that will never be corrected).

typename TFunctionPointerMap::const_iterator it;
Xeo
  • 129,499
  • 52
  • 291
  • 397
David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489