开发者

C++: Return pointer to template subclass

开发者 https://www.devze.com 2023-02-23 05:39 出处:网络
What is the syntax for doing somethinglike 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&l

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)
}
0

精彩评论

暂无评论...
验证码 换一张
取 消