我正在尝试将一个项目从 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/