Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the legal syntax to define nested template?

Tags:

c++

templates

I have the following nested template

class A {
    template <typename T> class B {
        template <typename U> void foo(U arg);
    };
};

I am trying to define the nested template like so:

template <typename T, typename U> void
A::B<T>::foo(U arg) {...}

But am getting declaration is incompatible with function template error. What's the legal syntax to do so?

like image 605
mchen Avatar asked May 09 '13 20:05

mchen


People also ask

How to define template class in cpp?

Templates in c++ is defined as a blueprint or formula for creating a generic class or a function. To simply put, you can create a single function or single class to work with different data types using templates. C++ template is also known as generic functions or classes which is a very powerful feature in C++.

What does template typename t mean?

" typename " is a keyword in the C++ programming language used when writing templates. It is used for specifying that a dependent name in a template definition or declaration is a type.

Which of the following best define the syntax for template function?

3. Which of the following best defines the syntax for template function ? Explanation: Both A or B is the syntax for template function. Explanation: Templates are abstract recipe for producing a concrete code, and it is used for Both A and B options.


1 Answers

You need to separate the template declarations:

template <typename T>
template <typename U>
void
A::B<T>::foo(U arg) { … }
like image 94
Konrad Rudolph Avatar answered Sep 23 '22 16:09

Konrad Rudolph