Move method definition for template nested class outside declaration

Vladislav

Is it possible to move method definition outside declaration?

template <typename T1>
class A
{
  template <bool T2>
  class B;

  template<>
  class B<true>
  {
    void f() { /* Do smg */ }
  }
  class B<false>
  {
    void f() { /* Do smg else */ }
  }
}

If I try to define f() outside class declaration, like this

template <typename T1>
template <>
void A<T1>::B<true>::f() { /* Do smg */ }

compiler gives error C3855: template parameter T2 is incompatible with the declaration.

Barry

You cannot explicitly specialize a class member template of a non-specialized class template, from [temp.expl.spec]:

In an explicit specialization declaration for a member of a class template or a member template that appears in namespace scope, the member template and some of its enclosing class templates may remain unspecialized, except that the declaration shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized as well.

Even the explicit specialiation of B inside of the definition of A is ill-formed. If you need to do such a thing, I would simply not use a member class template for B.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

inner class method definition outside of a template class

From Dev

Move function outside class definition

From Dev

declaration of templated function (over container type) inside class and definition of it outside a template class over container type-

From Dev

Partial Template specialization definition outside of class definition

From Dev

Partial Template specialization definition outside of class definition

From Dev

How to separate definition and declaration of child template class

From Dev

Template class method declaration failed

From Dev

C++ Nested class in class template declaration

From Dev

Method definition need to use private declaration of a class

From Dev

TypeScript - How to add a method outside the class definition

From Dev

Reference instance method outside class definition

From Dev

TypeScript - How to add a method outside the class definition

From Dev

Nested class declaration: template vs non-template outer class

From Dev

Forward declaration of template class nested inside template class

From Dev

Nested class declaration: template vs non-template outer class

From Dev

Unrecognizable template declaration/definition

From Dev

Define operator[]() (array subscription) for template class outside of class definition

From Dev

Python - declare method name in dictionary with method definition in outside class

From Dev

Python - declare method name in dictionary with method definition in outside class

From Dev

double-colon (::) before method declaration in class definition

From Dev

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

From Dev

In template class member function body outside class definition, when are template parameters required?

From Dev

Nested class definition outside outer class's, while outer class contains instance of inner class

From Dev

Using header files to make an ADT: declaration of ‘int Queue::size()’ outside of class is not definition [-fpermissive]

From Dev

How do I define a template member function outside of a full specialized template class's definition?

From Dev

How do I define a template member function outside of a full specialized template class's definition?

From Dev

java class only declaration no definition

From Dev

PHP Array Declaration With Class Definition

From Dev

Helper function declaration outside class?

Related Related

  1. 1

    inner class method definition outside of a template class

  2. 2

    Move function outside class definition

  3. 3

    declaration of templated function (over container type) inside class and definition of it outside a template class over container type-

  4. 4

    Partial Template specialization definition outside of class definition

  5. 5

    Partial Template specialization definition outside of class definition

  6. 6

    How to separate definition and declaration of child template class

  7. 7

    Template class method declaration failed

  8. 8

    C++ Nested class in class template declaration

  9. 9

    Method definition need to use private declaration of a class

  10. 10

    TypeScript - How to add a method outside the class definition

  11. 11

    Reference instance method outside class definition

  12. 12

    TypeScript - How to add a method outside the class definition

  13. 13

    Nested class declaration: template vs non-template outer class

  14. 14

    Forward declaration of template class nested inside template class

  15. 15

    Nested class declaration: template vs non-template outer class

  16. 16

    Unrecognizable template declaration/definition

  17. 17

    Define operator[]() (array subscription) for template class outside of class definition

  18. 18

    Python - declare method name in dictionary with method definition in outside class

  19. 19

    Python - declare method name in dictionary with method definition in outside class

  20. 20

    double-colon (::) before method declaration in class definition

  21. 21

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

  22. 22

    In template class member function body outside class definition, when are template parameters required?

  23. 23

    Nested class definition outside outer class's, while outer class contains instance of inner class

  24. 24

    Using header files to make an ADT: declaration of ‘int Queue::size()’ outside of class is not definition [-fpermissive]

  25. 25

    How do I define a template member function outside of a full specialized template class's definition?

  26. 26

    How do I define a template member function outside of a full specialized template class's definition?

  27. 27

    java class only declaration no definition

  28. 28

    PHP Array Declaration With Class Definition

  29. 29

    Helper function declaration outside class?

HotTag

Archive