Solved

Type / Pointer Question

Posted on 2006-06-13
3
173 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

773 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