Skip to main content
GameDev.net gamedev.net
🔒 Locked

new operator returning NULL (HELP)

Started by omaha_os3 Jan 5, 2002 at 7:33 PM 4 replies 500+ views
Original Post
omaha_os3
omaha_os3
I have a class CQuadtreeNode. I have been using this class for a few weeks now, and last night I started making some changes. Out of nowhere, I cannot create instances of it anymore. Every time I try a NodePtr = new CQuadtreeNode(); it is returning NULL. Except for the first time. I create one of these objects as the root node in my CQuadtree class, but I cannot create any of its children. I have not modified anything in the constructors or anything like that, and the code was working fine yesterday, so I''m extremely confused. If anyone has some idea of what might be going on I would really appreciate it.
omaha_os3
omaha_os3
Here's the code:
    
class CQuadtree;

class CQuadtreeNode{

friend class CQuadtree;

public:
CQuadtreeNode();
~CQuadtreeNode();

void Render(CCamera& camera);
CVector3f* GetControlPosition() { return &ControlPosition }

float Size;


private:

CQuadtreeNode* ChildPointers[4];

unsigned short* IndexPointer;

CVector3f ControlPosition;
};


And here is the constructor:
  
CQuadtreeNode::CQuadtreeNode()
{
// set all the child nodes to null

for(int tempCounter=0; tempCounter<4; tempCounter++)
{
ChildPointers[tempCounter]=NULL;
}
IndexPointer = NULL;

Size = 0;
ControlPosition.Assign(-1, -1, -1);
}


Edited by - omaha_os3 on January 5, 2002 8:43:45 PM
omaha_os3
omaha_os3
hrm.. that may have possibly fixed that problem, but now all my other classes seem to need the same changes. I get the feeling that there is some deeper issue, i can''t understand why this would be happening today but not yesterday.
Bloodshot Eye
Bloodshot Eye
I think our Anonymous friend is right you only need ()''s if you are passing parameters to the constructor e.g.

MyClass* var = new MyClass; //use default constructor

int val = 2;
MyClass* var2 = new MyClass(val); //use constructor taking int

From Effective C++:
"There are three common syntactic forms for getting new objects of type T...
new T;
new T(constructor arguments);
new T[size];"
Scott Meyers Effective C++ p26.

Hope this helps.

Ryan.
When things are dim give ''em VIM
omaha_os3
omaha_os3
it seems to work either way. I gave up and rewrote most of the quadtree code and it''s working well (if not quite as fast as i hoped for).

thanks for the help, though.


-Alan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.