Home > Net >  Nested Classes with Template
Nested Classes with Template

Time:06-18

I'm having issues using a nested class with a template. The first snippet is provided, I just have to implement it.

 template <typename T>
class a {
   public:
      class b {
         public:
            func(); 

I thought the implementation would look something like this, but it isn't working.

    template<typename T>
    a<T>::b<T>::func(){}

CodePudding user response:

There's not much wrong with your start. You just need to to tie it together.

template <typename T>
class a {
public:
    class b {
    public:
        void func();  // return type missing
    }; // missing
}; // missing

template <typename T>
void a<T>::b ::func() {}
//          ^ not <T>

Demo

  • Related