c++: C2783 error instanting class template

284 views Asked by At

Excuse me in advance for my bad english..i'm developing my own STL and i have some problem using template. This is the main structure of the my List class:

List.h

template <class T, class N>
class List{

   public:
          //public methods

   private:
          //private methods
}

Ok, now i need to implement a member function "sort" that will sort the elements of the list, but in this sort function i need to istantiate a List object. I found a solution implementing that function in a different module in this way:

AuxiliaryFunction.h

#include<List.h>
template <class List>
void sort(Lista & l){
   List A; //Works fine!
   ..
}

But in this way i have to call the sort function by doing this:

sort(ListObject);

instead of

ListObject.sort();

How can I do the same thing but with a member function of the List class? What would be different if the List class was an abstract class like the following code?

 template <class T, class N>
    class List{

       public:
              typedef T ElemType;
              typedef P position;

              virtual void create() = 0;
              virtual bool empty() = 0;
              ..
              void merge(Lista< T, N > &, Lista< T, N > &);
              ...
       private:
              //private methods
    }

Can be a template template parameter be a solution? I tried by doing something like this

 template <class T, class N>
    class List{
         ...
         template <template <class T,class N> class List> sort(){
              List A;
              ..
         }
    }

but a C2783 error ('could not deduce template argument for List') appear when i write

ListObject.sort();

Any kind of help will be appreciated :)

1

There are 1 answers

1
Greg Hewgill On

It sounds like you're looking for something like this:

template <class T, class N>
class List{
     ...
     void sort(){
          List<T, N> A;
          ..
     }
}