Link to home
Start Free TrialLog in
Avatar of LuckyLucks
LuckyLucks

asked on

template class as a member

Hi

I get this error:

'MyClass' use of class template requires template argument list

My template class is as follows:

template <class T=int> class MyClass{
:
:
}

Another class has this template class as members.

#include "MyClass.h"
class B{
     private:
          MyClass a; //This line gives me the above mentioned error
    :
    public:
         B(MyClass in): a(in) {}
}

what am i doing wrong?

I wanted to do something like this:
MyClass<T>  a;


where the type of a i.e. the member  would be defined by what's passed in to the constructor. Is this possible?
 Can the type of a member be a template class, whose type parameter (T=int or float etc) be defined at compile time by what's passed in the constructor?
SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial