Override of operator new(size_t nSize)

kccarter's Avatar
Newbie Member
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's Avatar, Join Date: Jul 2004
Go4Expert Founder
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's Avatar, Join Date: Dec 2006
Team Leader
Access to the heap is via pointers. Perhaps you could explain exactly what you're trying to achieve?
kccarter's Avatar
Newbie Member
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
DaWei's Avatar, Join Date: Dec 2006
Team Leader
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?