Search code examples
c++templatestype-deduction

typeindependent object of template class


I am stuck again...

I have this template class:

template <typename a,typename b,typename c>
class myclass
{...};

I would like to declare an object of this class:

myclass<a,b,c> x;

This obviously does not work and I don't seem to be able to work out how to declare this object or if it even is possible.

I can make an object like this:

myclass<int,double,int> x;

But I don't want to specify the types of a,b,c.


Solution

  • You need to declare it in template function or class, if I understand you correctly.

    template <typename a,typename b,typename c>
    void F(){
       myclass<a,b,c> x;
       ...
    }
    

    Otherwise it is forbidden by C++ and logic.