|
| audinue (35) | |||
| Anyone know how to invoke constructor in the malloc/realloc-ed classes? I have this code for reference:
Thanks in advance. | |||
| satm2008 (151) | |
| Not sure if malloc() works like new opeartor in C++ in terms of calling a default constructor. I guess it would call at least a base/default constructor but your code would give you a compiler error as default constructor is missing. In C++, the new operator can be given to call a parameterized constructor for the class/object being allocated. Just try adding a default constructor and compile it. I guess it would be OK. Good luck :) | |
| audinue (35) | |
| Oh my... I just wonder to make an ObjectPool (with constructors),... using malloc/realloc/free. But I think it wouldn't be possible in C++, isn't it? *sob* | |
| hooked (4) | |||
Maybe you can do it like this:
but I am not sure if it can work because I am not sure if it is in ISO | |||
| helios (4790) | |
| Constructors can't be called directly. | |
| jsmith (3099) | |
| You must use new when instantiating classes. You cannot use malloc. | |
This topic is archived - New replies not allowed.
