Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Type / Pointer Question

Posted on 2006-06-13
Medium Priority
179 Views
Octree      *m_children[8];

Is this:

A pointer to an array of OCTree's

0
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

LVL 39

Accepted Solution

itsmeandnobodyelse earned 2000 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];
}
{
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

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

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

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
###### Suggested Courses
Course of the Month7 days, 18 hours left to enroll