Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Override of operator new(size_t nSize) (http://www.go4expert.com/forums/override-operator-sizet-nsize-t3463/)

kccarter 18Mar2007 22:03

Override of operator new(size_t nSize)
what i am trying to do is this:

NeoGenesis::CNeoObject m_Obj = new NeoGenesis::CNeoObject();

this compiles with error: error C2440: 'initializing' : cannot convert from 'NeoGenesis::CNeoObject *' to 'NeoGenesis::CNeoObject' c:\Users\Almighty\Documents\Visual Studio 2005\Projects\NeoGenesis\NeoGenesis\NeoGenesis.cpp

the thing I do not want the m_Obj to be a pointer. the current new override is written as follows.

void* CNeoObject::operator new(size_t nSize)
return malloc(nSize);

how do I go about doing this?

shabbir 18Mar2007 23:59

Re: Override of operator new(size_t nSize)
NeoGenesis::CNeoObject m_Obj = new NeoGenesis::CNeoObject();
should be in C++ as
NeoGenesis::CNeoObject *m_Obj = new NeoGenesis::CNeoObject();

because pointers in C++ are defined with *

DaWei 19Mar2007 00:03

Re: Override of operator new(size_t nSize)
Access to the heap is via pointers. Perhaps you could explain exactly what you're trying to achieve?

kccarter 19Mar2007 06:11

Re: Override of operator new(size_t nSize)
well I am at some point will have a game engine built from the ground up. I am not interested in takeing a existing game engine and doing my thing I want to build one and re-inforce what I know with c++ and how it is done. yes I eventually just might make a game but I want to start at the gorund level with an object then move that object into a collection list<ResourceManager template> and progress write on down the line. I may have mixed up c++ and C# in the initial getting started. as soon as I get the collections working I plan to move on to a memorypool manager and so forth. I am also a student and this will cover everything I need to know. data structures, algorythms, memory management and so forth.


DaWei 19Mar2007 06:35

Re: Override of operator new(size_t nSize)
You don't have to instantiate objects on the heap. If you do, they'll be referenced by pointers. Consider this: mission critical or life support systems don't use the heap in any important way (if at all). What if you asked for memory and didn't get it?

All times are GMT +5.5. The time now is 05:51.