T
Timo Qvist
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
use
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?
Thanks!
/tq
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
use
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?
Thanks!
/tq