May 29, 2012 at 2:39pm UTC
Hey all,
When I compile my program I get 19 same errors that say : error C4519: default template arguments are only allowed on a class template.
for every class in the program there is a tempalte and every class inherits from other classes.
Header code example :
template<class T> class Point
{
public:
T x;
T y;
Point(T _x=0,T _y=0): x(_x),y(_y){}
void move(T _x,T _y)
{
x+=_x;
y+=_y;
}
};
class Shape
{
public:
virtual void print()=0;
virtual Shape* clone()=0;
virtual void extend(int i)=0;
virtual void move(int x,int y)=0;
};
template<class X, class T=Point<X>>
class Circle:public Shape
{
T center;
public:
X r1;
Circle();
Circle(Point<X>, X r1);
Circle(X r1,X x,X y);
void move(int x,int y);
void print();
void extend(int i);
Shape* clone();
};
This is one of main code functions that gives that error message :
template<class X,class T=point<X> >
Circle<X,T>::Circle(X a, X b,X c)
{
center=Point<X>(b,c);
r1=a;
}
I have to use templates and inheritance !!
Please help... Thank u
May 29, 2012 at 2:43pm UTC
maroun wrote:template <class X, class T=Point<X>>
This needs to be:
template <class X, template <typename > class T>
Wazzak
Last edited on May 29, 2012 at 2:46pm UTC
May 29, 2012 at 2:45pm UTC
Remove the default template argument from the function definition.
May 29, 2012 at 3:03pm UTC
@Framework what do you mean in <typename> ?? int , char .. ??
Point is also a function , and I want the type of its variabels to be decided by X.
And then I can declare a variable 'center' for example : T center; (is a type of point that its variables are type of X).
@Peter87 if I understand u correctly and I'll remove the default template, i'll have a problem with undeclared Type X for function variables , as well as with center in the function.
Last edited on May 29, 2012 at 3:18pm UTC
May 29, 2012 at 6:54pm UTC
But then I need to send in main the exact template and I can't use for example this main: Circle<char>*ch=new Circle<char>(2,3,3);
right ??