judeclarke
judeclarke

Reputation: 1116

Templated class and type return type for a member function

If possible, I would like to have a function in a class that returns a templated class, where the class and the class template value are template parameters. For example,

class AClass
{
public:
    template<typename ClassType, typename ClassTemplateType>
    ClassType<ClassTemplateType>* TestFunction() { return NULL; }
};

However, if I were to do something like this I will get errors such as

error C2988: unrecognizable template declaration/definition

error C2059: syntax error : '<'

error C2143: syntax error : missing ';' before '}'

error C2238: unexpected token(s) preceding ';'

Is it possible to do something as I have provided, and if so, how so? If it is not, why not and is there something else that could be suggested?

Upvotes: 0

Views: 115

Answers (1)

Seth Carnegie
Seth Carnegie

Reputation: 75150

The syntax for template template parameters is

template<template<typename> class ClassType, typename ClassTemplateType>
ClassType<ClassTemplateType>* TestFunction() { return NULL; }

Upvotes: 4

Related Questions