error C2614: 'CYYYRegister' : illegal member initialization:'CRequest' is not a base or member

A

Angus

Hello

I am trying to understand an issue which I know how to fix but don't
know why it works.

Getting this error:
error C2614: 'CYYYRegister' : illegal member initialization:
'CRequest' is not a base or member

Code is below. If I change class CXXXRequest slightly as below:

class CXXXRequest : public virtual CRequest

Then the error goes away.

Why? Why do I need the virtual keyword for compiler to realise that
CRequest is a base?


#include <string>
#include <iostream>


struct message_t
{
long id;
std::string strItem;
};

class TmMessage
{
public:
TmMessage(message_t *_msg) : msg(_msg) {}
message_t* GetMsg() const { return msg; }

protected:
message_t* msg;
};

class CRequest : public TmMessage
{
public:
CRequest::CRequest(int clientId, message_t *_msg)
: TmMessage(_msg)
{
std::cout << "CRequest::CRequest(int clientId, message_t *_msg)" <<
std::endl;
}
void CRequest::Options(unsigned idx, ...)
{
std::cout << "CRequest::Options" << std::endl;
}
};

class CXXXRequest : public /*virtual*/ CRequest
{
public:
CXXXRequest::CXXXRequest(int clientId, message_t *msg)
: CRequest(clientId, msg){}

int CXXXRequest::Invoke()
{
std::cout << "CXXXRequest::Invoke" << std::endl;
return 0;
}
};

class CYYYRegister : public CXXXRequest
{
public:
CYYYRegister(int clientId, message_t *msg) :
CRequest(clientId, msg),
CXXXRequest(clientId, msg)
{
std::cout << "CYYYRegister(int clientId, message_t *msg)" <<
std::endl;
}
int CYYYRegister::Invoke()
{
std::cout << "CYYYRegister::Invoke()" << std::endl;
}
};



int main()
{
int clientid = 1;

message_t mymsg;
mymsg.id = 7;
mymsg.strItem = "msg item";
CYYYRegister y(clientid, &mymsg);

CXXXRequest x(clientid, &mymsg);

message_t* pMsg = y.GetMsg();

int ret = x.Invoke();


return 0;
}
 
L

lotussfly

because at that line,you have initialnized two base,two Crequest,only
use virtual you can keep ther are the only base!
sorry about my poor writing English.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top