Constructor Overload Problem in C++ Inheritance
- by metdos
Here my code snippet:
class Request
{
public:
Request(void);
………..
}
Request::Request(void)
{
qDebug()<<"Request: "<<"Hello World";
}
class LoginRequest :public Request
{
public:
LoginRequest(void);
LoginRequest(QDomDocument);
……………
}
LoginRequest::LoginRequest(void)
{
qDebug()<<"LoginRequest: "<<"Hello World";
requestType=LOGIN;
requestId=-1;
}
LoginRequest::LoginRequest(QDomDocument doc){
qDebug()<<"LoginRequest: "<<"Hello World with QDomDocument";
LoginRequest::LoginRequest();
xmlDoc_=doc;
}
When call constructor of Overrided LoginRequest
LoginRequest *test=new LoginRequest(doc);
I came up with this result:
Request: Hello World
LoginRequest: Hello World with QDomDocument
Request: Hello World
LoginRequest: Hello World
Obviously both constructor of LoginRequest called REquest constructor.
Is there any way to cape with this situation?
I can construct another function that does the job I want to do and have both constructors call that function. But I wonder is there any solution?