Override of operator new(size_t nSize)

Newbie Member
18Mar2007,22:03   #1
kccarter's Avatar
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?
Go4Expert Founder
18Mar2007,23:59   #2
shabbir's Avatar
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 *
Team Leader
19Mar2007,00:03   #3
DaWei's Avatar
Access to the heap is via pointers. Perhaps you could explain exactly what you're trying to achieve?
Newbie Member
19Mar2007,06:11   #4
kccarter's Avatar
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.

Kenneth
Team Leader
19Mar2007,06:35   #5
DaWei's Avatar
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?