C++: Return pointer to template subclass
What is the syntax for doing something like this? When I try to compile the code below it tells me that a ';' was expected before '*'
, pointing to the return type of the function, 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 detail开发者_StackOverflow中文版s)
}
You are missing the typename
keyword. See this question for more details on why typename
is required. This code should compile:
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)
}
精彩评论