Read-only archive of the All About Symbian forum (2001–2013) · About this archive

Help: returning a TBuf does not work!

1 replies · 1,922 views · Started 23 November 2004

I have a method in which I define a TBuf<20> (stack-based). I want to return exactly this Tbuf, as an automatic, stack-based copy. Simple and plain... but it doesn't work! It seems that my data in the descriptor gets mixed up somehow, you can see some things while debugging, but it's not an identical copy!
I did it like this way:

TDes foo()
{
TBuf<20> output;
//... output gets properly (!) filled
return output;
}

called like this:
TBuf<20> input;
input = foo();

What's wrong? 😞 I've tried almost everything it seems to me!

Hi!

You cannot simply return a descriptor, you can only return a reference to descriptor. Modify your function as follows:

TDes & foo()

Leave the rest without change.