Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error C2614: 'CYYYRegister' : illegal member initialization:'CRequest' is not a base or member

Reply
Thread Tools

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

 
 
Angus
Guest
Posts: n/a
 
      03-06-2008
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;
}
 
Reply With Quote
 
 
 
 
lotussfly@gmail.com
Guest
Posts: n/a
 
      03-06-2008
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't take pointer-to-member of protected member of base class K. Frank C++ 8 03-22-2012 06:50 PM
Re: Error python + cx_Oracle :Oracle-Error-Message: ORA-01036:illegal variable name/number Ian Kelly Python 0 01-04-2011 09:14 PM
illegal reference to non-static member Gabrielle A. Grün C++ 2 01-07-2006 02:17 AM
illegal call of non-static member compile error question Ook C++ 7 10-20-2005 04:12 AM
Can Derived class static member access protected member from base class? Siemel Naran C++ 4 01-12-2005 06:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57