c++ - 表达式后预期为 ';'

标签 c++ factory

我正在尝试将一个项目从 Windows 移植到 Mac。我在编译 CFactory 类时遇到问题。我将尝试说明问题。

这是我在 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
}

当我尝试编译时,编译器提示:

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

为什么会这样?我错过了什么?

注意:此项目可在 MSVC 上正确编译。

谢谢。

最佳答案

在引用依赖类型时,您缺少必需的 typename 关键字。 Microsoft Visual Studio 错误地接受了没有 typename 的代码(这是 VS 中的一个众所周知的错误,永远不会得到纠正)。

typename TFunctionPointerMap::const_iterator it;

关于c++ - 表达式后预期为 ';',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155109/

相关文章:

.NET 工厂模式

java - 如何为给定的字符串创建唯一的序列号?

c++程序,用于将具有恒定(但未知)列数的未知大小的csv文件(仅填充 float )读取到数组中

c++ - 将纪元时间转换为 "real"日期/时间

c++ - 有人可以为虚函数解释这种行为吗?

JavaFX 2 TableView : different cell factory depending on the data inside the cell

c++ - SQL 查询返回 DB_E_NOTABLE

c++ - 在 BOOST 中禁用异常?

c++ - 扩展此 C++ 工厂实现的最佳方法?

javascript - 堆中的本地对象和工厂模式