How to separate definition and declaration of child template class

lmcdowall

If I have a template class defined as:

#ifndef A_HPP
#define A_HPP

template<class T>
class A
{
public:
  int doSomething(int in, bool useFirst);

private:
  template<int CNT>
  class B
  {
  public:
    int doSomething(int in);
  };

  B<2> first;
  B<3> second;
};

#include "a_imp.hpp"

#endif

Now I can go about having a declaration for A::doSomething in an implementation header file like this

#ifndef A_IMP_HPP
#define A_IMP_HPP

template<class T>
int A<T>::doSomething(int in, bool useFirst)
{
  if (useFirst)
    return first.doSomething(in);
  return second.doSomething(in);    
}

#endif

However I do not know how I go about making the declaration for the child class's method. Is it even possible or do I have to do one of the other two ways I can think of doing this, namely defining the methods in the main header or declare the class outside of A.

Please note that I am using C++11 so if this is only doable in that it will still work for me, though a C++98 solution would be good for other people.

iavr

Not sure if this is what you're asking, but I guess you need something like this:

 template<class T>
 template<int CNT>
 int A<T>::B<CNT>::doSomething(int in)
 {
    return /*...*/;
 }

Note that the template keyword appears twice, first for the template parameters of A, then for the parameters of nested class 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

How to separate definition from the declaration for a class template using 'extern' in C++11 in a library (dll, so,..)

From Dev

Unrecognizable template declaration/definition

From Dev

Move method definition for template nested class outside declaration

From Dev

How do I extend a TypeScript class definition in a separate definition file?

From Dev

How to achieve forward declaration of template class

From Dev

Separate inline class member function declaration and definition to different files (header and source)

From Dev

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

From Dev

How to implement partial specialized template on void separate from definition?

From Dev

java class only declaration no definition

From Dev

PHP Array Declaration With Class Definition

From Dev

Separate enum declaration and definition in C++11

From Dev

Separate declaration from definition of array of int in java

From Dev

C++, partial specialization of 2-argument class template: unable to match function definition to an existing declaration

From Dev

How do i separate a class definition into 2 header files?

From Dev

Template explicit instantiation (definition and declaration) in gcc

From Dev

Is a class declaration allowed after a class definition?

From Dev

Class' Struct's function declaration in header and definition in cpp. lnk2019 when using function in separate lib

From Dev

c++ type arguments are omitted in template declaration. However, how about in the definition of member function?

From Dev

Template class method declaration failed

From Dev

Conditional reference declaration in template class

From Dev

How do I write a proper class definition & declaration when a member is a user defined class?

From Dev

Method definition need to use private declaration of a class

From Dev

OpenCV - Ptr syntax and class definition / declaration - confusion?

From Dev

Partial Template specialization definition outside of class definition

From Dev

Partial Template specialization definition outside of class definition

From Dev

What kind of class template definition is this?

From Dev

Clean way to separate functions/subroutine declaration from definition in Fortran 90

From Dev

Clean way to separate functions/subroutine declaration from definition in Fortran 90

From Dev

Separate class declaration from it's implementation in PHP

Related Related

  1. 1

    How to separate definition from the declaration for a class template using 'extern' in C++11 in a library (dll, so,..)

  2. 2

    Unrecognizable template declaration/definition

  3. 3

    Move method definition for template nested class outside declaration

  4. 4

    How do I extend a TypeScript class definition in a separate definition file?

  5. 5

    How to achieve forward declaration of template class

  6. 6

    Separate inline class member function declaration and definition to different files (header and source)

  7. 7

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

  8. 8

    How to implement partial specialized template on void separate from definition?

  9. 9

    java class only declaration no definition

  10. 10

    PHP Array Declaration With Class Definition

  11. 11

    Separate enum declaration and definition in C++11

  12. 12

    Separate declaration from definition of array of int in java

  13. 13

    C++, partial specialization of 2-argument class template: unable to match function definition to an existing declaration

  14. 14

    How do i separate a class definition into 2 header files?

  15. 15

    Template explicit instantiation (definition and declaration) in gcc

  16. 16

    Is a class declaration allowed after a class definition?

  17. 17

    Class' Struct's function declaration in header and definition in cpp. lnk2019 when using function in separate lib

  18. 18

    c++ type arguments are omitted in template declaration. However, how about in the definition of member function?

  19. 19

    Template class method declaration failed

  20. 20

    Conditional reference declaration in template class

  21. 21

    How do I write a proper class definition & declaration when a member is a user defined class?

  22. 22

    Method definition need to use private declaration of a class

  23. 23

    OpenCV - Ptr syntax and class definition / declaration - confusion?

  24. 24

    Partial Template specialization definition outside of class definition

  25. 25

    Partial Template specialization definition outside of class definition

  26. 26

    What kind of class template definition is this?

  27. 27

    Clean way to separate functions/subroutine declaration from definition in Fortran 90

  28. 28

    Clean way to separate functions/subroutine declaration from definition in Fortran 90

  29. 29

    Separate class declaration from it's implementation in PHP

HotTag

Archive