×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Error: can't cast TPtr to TDes in function call in S60 3rd ed.

    Is this really true:

    When I compile GCCE UREL target on command line (S60 3rd edition), TPtr can't be cast to TDes (in Visual Studio it can (for target WINSCW UDEB) and the program works fine). I've got a following piece of code:

    I call ReadLongDBColL:
    ...
    HBufC* url = HBufC::NewLC( aView.ColLength(urlcol) );
    ReadLongDBColL( aView, urlcol, (TDes&) url->Des() );
    ...

    and ReadLongDBColL is defined as:

    TInt CMyDB::ReadLongDBColL( RDbView& aView, const TInt aColNo, TDes& aRetVal )

    Then I get the following error:

    ..\\src\\db\\Moviedb.cpp:8730: error: conversion to non-const reference type `class TDes&' from rvalue of type `TPtr16'

    HOWEVER if I write the calling code as this:

    TDes joo=url->Des();
    ReadLongDBColL( aView, urlcol, joo );

    It works! Hallelujah!!!

    Is my compiler broken or am I?

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: Error: can't cast TPtr to TDes in function call in S60 3rd ed.

    You :-)
    Casting a variable to the reference of itself is simply not possible. References are not casted from a variable, they are initialized with a variable.
    And reference-parameters need no treatment at all:
    Code:
    ReadLongDBColL( aView, urlcol, url->Des() );
    should work, since TPtr is a descendant of TDes.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Location
    Bengaluru, India
    Posts
    747

    Re: Error: can't cast TPtr to TDes in function call in S60 3rd ed.

    Quote Originally Posted by mmikkone
    Is this really true:
    ...
    HBufC* url = HBufC::NewLC( aView.ColLength(urlcol) );
    ReadLongDBColL( aView, urlcol, (TDes&) url->Des() );
    ...
    Please change your code as given below:

    Code:
    HBufC* url = HBufC::NewLC( aView.ColLength(urlcol) );
    TPtr urlPtr(url->Des());
    ReadLongDBColL( aView, urlcol, urlPtr);
    Hope this will work.

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Re: Error: can't cast TPtr to TDes in function call in S60 3rd ed.

    Quote Originally Posted by wizard_hu_
    You :-)
    Casting a variable to the reference of itself is simply not possible. References are not casted from a variable, they are initialized with a variable.
    And reference-parameters need no treatment at all:
    Code:
    ReadLongDBColL( aView, urlcol, url->Des() );
    should work, since TPtr is a descendant of TDes.
    What do you mean with all that? The code works in target WINSCW UDEB. I think references as pointers (I'm not sure!), except that they can't be null. When a reference is passed to a function, I think the address of the variable is actually passed just as if you would pass a pointer of a variable (???). So if you cast a variable in function call to a reference to itself, then the address of that variable is actually passed to the function. Am I right or am I wrong?

    Second thing: I already tried to write

    Code:
    ReadLongDBColL( aView, urlcol, url->Des() );
    But then the compiler gives me error:

    ..\\src\\db\\Mydb.cpp:8730: error: no matching function for call to `CMyDB:::ReadLongDBColL(RDbView&, TInt&, TPtr16)'

    That happens in both targets (WINSCW UDEB and GCCE UREL). That's why I tried the explicit cast.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Re: Error: can't cast TPtr to TDes in function call in S60 3rd ed.

    Quote Originally Posted by vin2ktalks
    Please change your code as given below:

    Code:
    HBufC* url = HBufC::NewLC( aView.ColLength(urlcol) );
    TPtr urlPtr(url->Des());
    ReadLongDBColL( aView, urlcol, urlPtr);
    Hope this will work.
    Thank you. It did work.

  6. #6
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: Error: can't cast TPtr to TDes in function call in S60 3rd ed.

    Btw, I don't think there is any situation where casting with descriptors is required. So if you find yourself doing that, think again.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    19

    Re: Error: can't cast TPtr to TDes in function call in S60 3rd ed.

    Quote Originally Posted by simo.salminen
    Btw, I don't think there is any situation where casting with descriptors is required. So if you find yourself doing that, think again.
    You had better read my post first.

Similar Threads

  1. RTP stack on S60 3rd edition
    By kit_walker in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2006-09-28, 14:37
  2. S60 2nd OR 3rd edition for new software development
    By patil_ruturaj in forum Mobile Java Tools & SDKs
    Replies: 3
    Last Post: 2006-06-30, 08:57
  3. S60 3rd Edition Device and Heap limitation!
    By khurshed79 in forum Symbian
    Replies: 6
    Last Post: 2006-06-29, 10:51
  4. How to call a function while dialog RunDL() is executing?
    By danparks in forum Symbian User Interface
    Replies: 2
    Last Post: 2005-09-30, 04:50
  5. How to call nonexported virtual function
    By zhang_guoqing in forum Symbian
    Replies: 0
    Last Post: 2004-07-26, 08:23

Posting Permissions

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