[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

explicit constructor call on casted void * (gcc 3.3.3)

From: Timo Qvist
Subject: explicit constructor call on casted void * (gcc 3.3.3)
Date: Tue, 30 Nov 2004 20:23:57 GMT

Hi, I know there is a proper way to do this but I find myself with a
void pointer returned from a malloc( sizeof( class T ) ) which gives me
a pointer to a memory area of the size of class T. The thing is, I need to
this data as a class object, but the constructor hasnt been called which
means I get
a zeroed out vptr table; so I tried this...

void foo(int a) {
T *newTptr = (T *)allocptr(); // returns a void * so casted...
    newTptr->T::T( a );

The second line explicitly calling the constructor actually works with MS
Visual C++ 7,
but not gcc 3.3.3 .... basically get a parse error.. I was kinda surprised
it worked
and am wondering whether someone can help me get it to work on gcc?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]