×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Feb 2007
    Posts
    91

    Question How to create an instance of a class derived from CActive class?

    Hi,

    I have derived one class from CActive class. For example,
    class CClientApp : public CActive
    {
    private:
    CTelephony* iTelephony;
    CTelephony::TBatteryInfoV1 iBatteryInfoV1;
    CTelephony::TBatteryInfoV1Pckg iBatteryInfoV1Pckg;

    public:
    CClientApp(CTelephony* aTelephony);
    void SomeFunction();

    private:
    void RunL();
    void DoCancel();
    };

    Now I want to create an instance of the derived class CClientApp.
    How should I create it?

    I have written the code as:

    {
    CTelephony *telephonyApi;
    telephonyApi = CTelephony::NewLC();

    CClientApp *batteryStrength;
    batteryStrength = new CClientApp(telephonyApi);
    }

    //The constructor for the derived class CClientApp
    CClientApp::CClientApp(CTelephony* aTelephony)
    : CActive(EPriorityStandard),
    iTelephony(aTelephony),
    iBatteryInfoV1Pckg(iBatteryInfoV1)
    {
    //default constructor
    iBatteryInfoV1.iStatus = CTelephony::EPowerStatusUnknown;
    }

    After compiling the program I am getting some linker error saying "undefined reference to vtable for CClientApp::CClientApp(CTelephony *iTelephony)"

    where I am wrong? Do I need to create an instance of CActive class also?
    Please help me.

    Waiting for your reply,
    ---Sumit

  2. #2
    Regular Contributor
    Join Date
    Jun 2004
    Location
    Helsinki, Finland
    Posts
    69

    Re: How to create an instance of a class derived from CActive class?

    You really should not do this
    ...
    CClientApp *batteryStrength;
    batteryStrength = new CClientApp(telephonyApi);
    ...

    on a C-type class (especially when inherited from another C-type class). You need to do the two-phase construction stuff with NewLC & ConstructL

    Other option might be using
    ...
    batteryStrength = new (ELeave)CClientApp(telephonyApi);
    ...

  3. #3
    Regular Contributor
    Join Date
    Feb 2007
    Posts
    91

    Re: How to create an instance of a class derived from CActive class?

    Thank you.

    I have changed my code to new (ELeave).

    ---Sumit

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How to create an instance of a class derived from CActive class?

    Quote Originally Posted by myohol
    batteryStrength = new (ELeave)CClientApp(telephonyApi);
    I recommend to use NewL for every C-Class.

  5. #5
    Regular Contributor
    Join Date
    Oct 2004
    Location
    Tokyo,Japan
    Posts
    289

    Thumbs up Re: How to create an instance of a class derived from CActive class?

    hi sumitv,

    there is some error indicating to 'vtable '.

    so check that you have implemented all the pure virtual functions (owned from the base) in the derived class you are trying to instantiate.

    Ensure that you have implemented the RunL() in the derived class .


    regards
    nEo

  6. #6
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How to create an instance of a class derived from CActive class?

    Quote Originally Posted by sumitv
    //The constructor for the derived class CClientApp
    CClientApp::CClientApp(CTelephony* aTelephony)
    : CActive(EPriorityStandard),
    iTelephony(aTelephony),
    iBatteryInfoV1Pckg(iBatteryInfoV1)
    {
    //default constructor
    iBatteryInfoV1.iStatus = CTelephony::EPowerStatusUnknown;
    }
    For the vtable Error You are getting i don't think you req. this.
    cahange it to
    Code:
    //The constructor for the derived class CClientApp
    CClientApp::CClientApp(CTelephony* aTelephony)
        : CActive(EPriorityStandard),
          iTelephony(aTelephony)
        {
        //default constructor
        	iBatteryInfoV1.iStatus = CTelephony::EPowerStatusUnknown;
        }

  7. #7
    Regular Contributor
    Join Date
    Feb 2007
    Posts
    91

    Smile Re: How to create an instance of a class derived from CActive class?

    Quote Originally Posted by navjotsingh1979
    hi sumitv,

    there is some error indicating to 'vtable '.

    so check that you have implemented all the pure virtual functions (owned from the base) in the derived class you are trying to instantiate.

    Ensure that you have implemented the RunL() in the derived class .


    regards
    nEo
    Yes the error is solved.
    Your are write. I had declared the functions RunL() and DoCancel() in the derived class but I did not implement that.

    Now I have written the function definitions for both the functions RunL() and DoCancel().
    And IT WORKS!!![]

    The error is resolved.

    Thanking you,
    ---Sumit

Similar Threads

  1. Replies: 2
    Last Post: 2007-03-14, 17:15
  2. How to add a class derived from CAkndialog?
    By swinglinewind in forum Mobile Java General
    Replies: 1
    Last Post: 2006-03-12, 17:25
  3. How can i create a mbm file with CFbsBitmap class?
    By fernandola in forum Symbian User Interface
    Replies: 3
    Last Post: 2005-12-15, 10:51
  4. cannot create class in system package
    By natrixnt in forum Mobile Java General
    Replies: 6
    Last Post: 2003-08-05, 08:47
  5. How can I create a mbm file with CFbsBitmap class?
    By fernandola in forum Symbian User Interface
    Replies: 1
    Last Post: 2003-02-26, 02:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×