TPtrC vs TText

Login to reply to this topic.
Fri, 2008-03-14 05:23
Joined: 2008-03-11
Forum posts: 12

Hi All,
I am beginner in symbian C++ . I have the following code :

_LIT(KT,"Good boy");
TBufC<12>buf(KT);
TPtrC ptr(buf);
TText *text= (TText*)ptr.Ptr();
console->Printf((TText*)text);

It gives the following error.
error C2664: 'Printf' : cannot convert parameter 1 from 'unsigned short *' to 'class TRefByValue'
No constructor could take the source type, or constructor overload resolution was ambiguous

I do not know where is the problem. Please help me urgent

Thanks in Advance
Satish Khatri


Fri, 2008-03-14 09:53
Joined: 2004-11-29
Forum posts: 1142
Re: TPtrC vs TText

Thats some crazy code you have there.

your problem is that Printf on the console does not take a TText* pointer, but a reference to a TDesC.

You can excange your crazy code blob with this:

_LIT(KT,"Good boy");
console->Printf(KT);

All the lines in there between, is totally unnecessary and just waste memory and CPU cycles.

Fri, 2008-03-14 11:50
Joined: 2008-03-11
Forum posts: 12
Re: TPtrC vs TText

Hi alh,

Thanks for Helping

Fri, 2008-03-14 16:51
Joined: 2007-09-23
Forum posts: 136
Re: TPtrC vs TText

I think you should ask yourself why you tried to cast it to a TText*?

If you see a function called Printf(TSausages& aSausages);

and instead of passing it a TSausages object you tried to pass it a pointer to a TElephant object would you expect it to compile? If not, then why did you attempt a similar thing with TDesC& and TText*?

  • Login to reply to this topic.