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

Discussion in 'C++' started by Angus, Mar 6, 2008.

  1. Angus

    Angus Guest

    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;
    }
     
    Angus, Mar 6, 2008
    #1
    1. Advertising

  2. Angus

    Guest

    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.
     
    , Mar 6, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    891
    Peter_Julian
    Oct 10, 2005
  2. Ook
    Replies:
    7
    Views:
    916
    David White
    Oct 20, 2005
  3. Replies:
    4
    Views:
    356
    Joe Greer
    Jul 25, 2008
  4. aaragon
    Replies:
    2
    Views:
    637
    James Kanze
    Nov 2, 2008
  5. Ian Kelly
    Replies:
    0
    Views:
    799
    Ian Kelly
    Jan 4, 2011
Loading...

Share This Page