Menu

Error on runing constructor

Anonymous
2002-09-19
2002-09-19
  • Anonymous

    Anonymous - 2002-09-19

    In ClassBrowser I have DataModel set with :
    Code generation options: Serialize, MFC serialize
    Document Clas Name: CBO

    Class browser has created classes: CBO and CBObjects with relation CBO <>-->> CBObject
    I have created clases:
    class CBO_A::public CBOObject
    class CBO_ATable::public CBOObject
    with relation:
    CBO_ATable <>-->>CBO_A

    Both CBO_A and CBO_ATable are derived from CBOObject because of serialization.

    Now in my MFC application I create these object as follow:

    CBO_ATable *pATable=new CBO_ATable;
    CBO_A *pA=new CBO_A(pATable);

    Program compiles ok, but on runing that code fatal error is generated on runing constructor of CBO_A.
    Precisely speaking on runing body of CBOObject::ConstuctorInclude
        INIT_MULTI_OWNED_PASSIVE(CBO, CBO, CBObject, CBObject)

    I'm confused. What is wrong? Does my relations are set correctly?

     
    • Jimmy Venema

      Jimmy Venema - 2002-09-19

      It seems the constructor used for CBO_ATable is incorrect.
      You are using a constructor, without argument. CBO_ATable, is derived from CBObject and should attach itself to an CBO object. It looks like you made the protected constructor public and use this constructor. This constructor should only be used for serializing back from file and creating the objects. Create a new constructor for class CBO_ATable, this will have as argument CBO* pCBO.
      The generated constructor of CBO_A assumes that the object pointed at by 'pATable' is attached to an CBO object. It calls pATable->GetCBO() and passes it as argument to the CBOObject contructor. Since you are using the wrong constructor for CBO_ATable, GetCBO() returns null resulting is the behaviour you witnessed.

      Jimmy Venema

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.