Solved

Type / Pointer Question

Posted on 2006-06-13
3
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

739 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