P
pantalaimon
I'm trying to write a GUI for a game I'm making. Till now I've always
done this: ChildClass(int x,int y) : ParentClass(x,y) whenever my
compiler complains about "no default constructor found". But in one of
my classes I need to do some calculations first and THEN call the
parent's constructor. Here is an example:
class ParentClass
{
public:
Parentclass(int sum);
};
class ChildClass : public ParentClass
{
public:
ChildClass(int x,int y)
{
int sum = x + y;
ParentClass(sum);
}
Problem is I don't know how to do it (if it is even possible). The
above code doesn't work. The compiler thinks I want to instantiate an
instance of the ParentClass.
Thanks in advance!
done this: ChildClass(int x,int y) : ParentClass(x,y) whenever my
compiler complains about "no default constructor found". But in one of
my classes I need to do some calculations first and THEN call the
parent's constructor. Here is an example:
class ParentClass
{
public:
Parentclass(int sum);
};
class ChildClass : public ParentClass
{
public:
ChildClass(int x,int y)
{
int sum = x + y;
ParentClass(sum);
}
Problem is I don't know how to do it (if it is even possible). The
above code doesn't work. The compiler thinks I want to instantiate an
instance of the ParentClass.
Thanks in advance!