Solved

Type / Pointer Question

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now