×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    46

    invalid conversion from TDesC8 * to HBufC8 *

    Hello

    I am new to Symbian C++, any help is greatly appreciated,

    I have defined a function as follows

    TDesC8* CsomeClass:: get _HBufC8_Ptr ()
    {
    Return i_hbufc8_ptr;
    }

    When i use :

    HBufC8* hbufcPtr = someObject-> get _HBufC8_Ptr();

    I get the error : invalid conversion from TDesC8* to HBufC8*

    Any ideas why ?

    Many thanks !

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    282

    Re: invalid conversion from TDesC8 * to HBufC8 *

    Welcome to forum nokia Dibo.

    Since C++ is a statically typed language so the compiler cannot directly convert an object to its subtype. You have upcasted an HBufC8* to TDesC* , so downcasting will require a static or reinterpret cast (dynamic casting isnt available with sdk compilers). Please change to code below:

    HBufC8* hbufcPtr = STATIC_CAST(HBufC8*,someObject-> get _HBufC8_Ptr());

    or

    HBufC8* hbufcPtr = (HBufC8*)(someObject-> get _HBufC8_Ptr());


    Hope that helps,
    VJ

  3. #3
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: invalid conversion from TDesC8 * to HBufC8 *

    There is no need to use casts with descriptors, in fact they should always be avoided.

    If you are returning a HBufC8* from a class and transferring ownership of that class then you should make the function return type a HBUfC8* also.

Similar Threads

  1. Error in packaging process :(
    By a-eqla3 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2008-07-24, 20:33
  2. Need one HTTP client example
    By vinayakak in forum Symbian Networking & Messaging (Closed)
    Replies: 15
    Last Post: 2008-01-06, 06:44

Posting Permissions

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