Solved

Type / Pointer Question

Posted on 2006-06-13
3
174 Views
Last Modified: 2010-04-01
Octree      *m_children[8];

Is this:

A pointer to an array of OCTree's

0
Comment
Question by:directxBOB
3 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 16900214
It is a  pointer to an array of OCTree pointers.

You need to set or initialize each of these pointers in the constructor (I assume m_children is a class member), e. g.

class MyClass
{
    Octree* m_children;

public:
    MyClass()
    {
        for (int i = 0; i < sizeof(m_children/sizeof(Octree*); ++i)
             m_children[i] = NULL;
    }
    ~MyClass()
   {
        for (int i = 0; i < sizeof(m_children/sizeof(Octree*); ++i)
        delete m_children[i];
   }
   void addChild()
   {
       for (int i = 0; i < sizeof(m_children/sizeof(Octree*); ++i)
            if (m_children[i] == NULL)
                m_children[i] = new Octree(... );
   }
}

Regards, Alex


};
0
 

Author Comment

by:directxBOB
ID: 16900323
Any idea on how to port this to C#

Vector OcTreeNode::dirs[8] = {Vector(-1,1,1),Vector(-1,1,-1),Vector(1,1,1),Vector(1,1,-1),Vector(-1,-1,1),Vector(-1,-1,-1),Vector(1,-1,1),Vector(1,-1,-1)};

Basically its the 8 directions for an OCtree
0
 
LVL 3

Expert Comment

by:jitendra_wadhwani
ID: 16900331
Very fine Alex....




sizeof(m_children/sizeof(Octree*);
 has a typo error... missing one closing bracket...

should be
sizeof(m_children)/sizeof(Octree*);

and it will be always 8 as it is hardcoded in this case
anyway

Initialization in conctructor is fine

But Before deleing in destructor there should be Check for NULL

delete m_children[i];


if(m_children[i]  !=  NULL)
    delete m_children[i];



Anyway the answer given by Alex is good.....






0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question