explicit constructor call on casted void *
From: Timo Qvist (timo.qvist_at_telia.com)
Date: 11/30/04
- Next message: Old Wolf: "Re: CAnnot find the compilation error in this circular list"
- Previous message: Alf P. Steinbach: "Re: Best way to access this file?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Nov 2004 20:23:04 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
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
- Next message: Old Wolf: "Re: CAnnot find the compilation error in this circular list"
- Previous message: Alf P. Steinbach: "Re: Best way to access this file?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|