How to use descriptor TPtr/TDes as class member

Login to reply to this topic.
Thu, 2005-04-07 14:23
Joined: 2005-03-02
Forum posts: 2
Hi all,
       
           I have a problem. I want to declare a TPtr/TDes variable in a class as a data member. Can it be possible. I have written the following code, but its giving error as "no appropriate default constructor available"

The code is as follows:

Code:
Code:
#include "e32base.h"
#include "e32def.h"
#include "e32std.h"

class CMyTestParm: public CBase
{
private:
TInt a;
TPtr d;
public:
void ConstructL();
~CMyTestParm();
static CMyTestParm* NewL();
static CMyTestParm* NewLC();
CMyTestParm();

};


CMyTestParm* CMyTestParm::NewL()
   {
   CMyTestParm* self = CMyTestParm::NewLC();
   CleanupStack::Pop(self);
   return self;
   }

CMyTestParm* CMyTestParm::NewLC()
   {
   CMyTestParm* self = new (ELeave) CMyTestParm;
   CleanupStack::PushL(self);
   self->ConstructL();
   return self;
   }

CMyTestParm::CMyTestParm()
{

}
void CMyTestParm::ConstructL()
{
// No implementation required

}


CMyTestParm::~CMyTestParm()
{
// delete d;
// d = NULL;
}

Thu, 2005-04-07 16:40
Joined: 2004-06-06
Forum posts: 205
How to use descriptor TPtr/TDes as class member
make a pointer.
TPtr * d;

Best regards,
Michal Laskowski

Thu, 2005-04-07 18:46
Joined: 2004-02-05
Forum posts: 176
How to use descriptor TPtr/TDes as class member
TPtr does not have a default constructor.  So in order to create a TPtr as a member variable in your class you must construct the TPtr using one of TPtrs provided constructors in your class's constructor initialization list.

TPtr's constructors
Code:
IMPORT_C TPtr16(TUint16 *aBuf,TInt aMaxLength);
IMPORT_C TPtr16(TUint16 *aBuf,TInt aLength,TInt aMaxLength);

Example:

Code:
//Calling TPtr iPtr using the 1st constructor above
CMyTestParm::CMyTestParm() : d(NULL,0)
{

}

Remember, TPtr does not actually own data, it points to data.  So if you create a TPtr, you don't delete it.

Fri, 2005-04-08 07:07
Joined: 2005-03-02
Forum posts: 2
How to use descriptor TPtr/TDes as class member
hi Dishneau,

              Thank you very much for this information. It helped so lot.
But I have another problem. Can you please solve it?

How can i assign value to the member variable iPtr (Tptr iPtr) and how to retrive it again. Its highly essential for my project.

regards

Balaraju

Quote from: dishneau
TPtr does not have a default constructor.  So in order to create a TPtr as a member variable in your class you must construct the TPtr using one of TPtrs provided constructors in your class's constructor initialization list.

TPtr's constructors
Code:
IMPORT_C TPtr16(TUint16 *aBuf,TInt aMaxLength);
IMPORT_C TPtr16(TUint16 *aBuf,TInt aLength,TInt aMaxLength);

Example:

Code:
//Calling TPtr iPtr using the 1st constructor above
CMyTestParm::CMyTestParm() : d(NULL,0)
{

}

Remember, TPtr does not actually own data, it points to data.  So if you create a TPtr, you don't delete it.
  • Login to reply to this topic.