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?
Edit: http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.3