1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Override of operator new(size_t nSize)

Discussion in 'C' started by kccarter, Mar 18, 2007.

  1. kccarter

    kccarter New Member

    Joined:
    Mar 18, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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::eek:perator new(size_t nSize)
    {
    return malloc(nSize);
    }

    how do I go about doing this?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    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 *
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Access to the heap is via pointers. Perhaps you could explain exactly what you're trying to achieve?
     
  4. kccarter

    kccarter New Member

    Joined:
    Mar 18, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  5. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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?
     

Share This Page