Forward declaration of template class nested inside template class

Louen

You can forward declare a template inner class inside a normal class, and use the defined type as any other forward declared type.

class Outer {
    template <int N> class Inner;
    typedef Inner<0> Inner0;
    Inner0* f();
};

template<int N>
class Outer::Inner {};

Now if Outer is itself a template class, is there a way to keep the declaration of Inner outside the declaration of Outer ? Something like :

template<typename T>
class Outer {
    template <int N> class Inner;
    typedef Inner<0> Inner0;
    Inner0* f();
};

template<typename T, int N> //This won't work
class Outer<T>::Inner {};

Is there a correct syntax to declare Outer with the right template parameters ?

Vlad from Moscow

Try the following

template<typename T>
template <int N>
class Outer<T>::Inner {};

According to the C++ Standard (14.5.2 Member templates)

1 A template can be declared within a class or class template; such a template is called a member template. A member template can be defined within or outside its class definition or class template definition. A member template of a class template that is defined outside of its class template definition shall be specified with the template-parameters of the class template followed by the template-parameters of the member template.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

std:forward inside a template class

From Dev

Forward class declaration with template using typename

From Dev

Forward declaration of (sdk) class containing template

From Dev

How to achieve forward declaration of template class

From Dev

why Specialized template class need forward declaration?

From Dev

Template Friend Class: Forward Declaration or...?

From Dev

Forward class declaration with template using typename

From Dev

Forward declaration of a template class c++

From Dev

C++ Nested class in class template declaration

From Dev

Nested class declaration: template vs non-template outer class

From Dev

Nested class declaration: template vs non-template outer class

From Dev

Using a class as a template parameter for a templated class with forward declaration

From Dev

Template Inside Template Class

From Dev

Class template inside a class template

From Dev

Forward Declaration of class as template param. Why does this work?

From Dev

Move method definition for template nested class outside declaration

From Dev

"Member declaration not found" in a nested template class in C++

From Dev

How to define a static member of a nested template (template class inside template class)

From Dev

Forward declaring a typedef for a template class

From Dev

Template class method declaration failed

From Dev

Conditional reference declaration in template class

From Dev

Nested class template specialization

From Dev

Nested class as a template parameter

From Dev

variadic template in nested class

From Dev

Resolve template with a nested class

From Dev

Explicit specialization of nested class template in class template

From Dev

How to reference the nested type of a nested template parameter inside a class?

From Dev

"class VARIABLE" in declaration of variable for template class?

From Dev

"class VARIABLE" in declaration of variable for template class?

Related Related

  1. 1

    std:forward inside a template class

  2. 2

    Forward class declaration with template using typename

  3. 3

    Forward declaration of (sdk) class containing template

  4. 4

    How to achieve forward declaration of template class

  5. 5

    why Specialized template class need forward declaration?

  6. 6

    Template Friend Class: Forward Declaration or...?

  7. 7

    Forward class declaration with template using typename

  8. 8

    Forward declaration of a template class c++

  9. 9

    C++ Nested class in class template declaration

  10. 10

    Nested class declaration: template vs non-template outer class

  11. 11

    Nested class declaration: template vs non-template outer class

  12. 12

    Using a class as a template parameter for a templated class with forward declaration

  13. 13

    Template Inside Template Class

  14. 14

    Class template inside a class template

  15. 15

    Forward Declaration of class as template param. Why does this work?

  16. 16

    Move method definition for template nested class outside declaration

  17. 17

    "Member declaration not found" in a nested template class in C++

  18. 18

    How to define a static member of a nested template (template class inside template class)

  19. 19

    Forward declaring a typedef for a template class

  20. 20

    Template class method declaration failed

  21. 21

    Conditional reference declaration in template class

  22. 22

    Nested class template specialization

  23. 23

    Nested class as a template parameter

  24. 24

    variadic template in nested class

  25. 25

    Resolve template with a nested class

  26. 26

    Explicit specialization of nested class template in class template

  27. 27

    How to reference the nested type of a nested template parameter inside a class?

  28. 28

    "class VARIABLE" in declaration of variable for template class?

  29. 29

    "class VARIABLE" in declaration of variable for template class?

HotTag

Archive