做这样的事情的语法是什么?当我尝试编译下面的代码时,它告诉我a ';' was expected before '*'
,指向函数的返回类型ResourceManager<T>::ResourceWrapper*
。
template<class T>
class ResourceManager
{
private:
struct ResourceWrapper;
ResourceWrapper* pushNewResource(const std::string& file);
};
// (Definition of ResourceWrapper not shown.)
template <class T>
ResourceManager<T>::ResourceWrapper* ResourceManager<T>::pushNewResource(
const std::string& file)
{
// (Irrelevant details)
}
答案 0 :(得分:10)
您错过了typename
关键字。有关为何需要typename
的详细信息,请参阅此question。这段代码应编译:
template<class T>
class ResourceManager
{
private:
struct ResourceWrapper;
ResourceWrapper* pushNewResource(const std::string& file);
};
// (Definition of ResourceWrapper not shown.)
template <class T>
typename ResourceManager<T>::ResourceWrapper* ResourceManager<T>::pushNewResource(
^^^^^^^^ const std::string& file)
{
// (Irrelevant details)
}