Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,917 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,742 people online right now. Registration is fast and FREE... Join Now!




Class containing itself

 
Reply to this topicStart new topic

Class containing itself

Pontus
1 Apr, 2008 - 02:01 AM
Post #1

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 530



Thanked: 2 times
Dream Kudos: 275
My Contributions
I'm working on A* pathfinding, It's almost complete but I'm stuck at 1 problem. Quite a bugger when ur finnaly busy on Pathfinding when u stumble across this blink.gif

CODE

class Node
{
public:
int x,y,f,g,h;
Node parent;
};


It Gives me an error : "Field parent has incomplete type"
I bet It's something dead easy but I just cant find it

This post has been edited by manhaeve5: 1 Apr, 2008 - 02:02 AM
User is offlineProfile CardPM
+Quote Post

martin_bg
RE: Class Containing Itself
1 Apr, 2008 - 02:39 AM
Post #2

New D.I.C Head
*

Joined: 20 Mar, 2008
Posts: 15

Hello!

I think the error comes because you can't instantiate a class in such a way. Try this:

CODE

class Node
{
public:
int x,y,f,g,h;
Node *parent;
};


and create the instance for the parent property at the point you need it.

Hope it's been of help to you!



User is offlineProfile CardPM
+Quote Post

Pontus
RE: Class Containing Itself
1 Apr, 2008 - 02:43 AM
Post #3

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 530



Thanked: 2 times
Dream Kudos: 275
My Contributions
Well, the problem with that is that the parent it is linked to is only temporaly, so it crashes
User is offlineProfile CardPM
+Quote Post

martin_bg
RE: Class Containing Itself
1 Apr, 2008 - 03:10 AM
Post #4

New D.I.C Head
*

Joined: 20 Mar, 2008
Posts: 15

QUOTE(manhaeve5 @ 1 Apr, 2008 - 03:43 AM) *

Well, the problem with that is that the parent it is linked to is only temporaly, so it crashes


Can't you just check whether the parent is there or not before you try to access it?

This post has been edited by martin_bg: 1 Apr, 2008 - 03:10 AM
User is offlineProfile CardPM
+Quote Post

Pontus
RE: Class Containing Itself
1 Apr, 2008 - 03:40 AM
Post #5

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 530



Thanked: 2 times
Dream Kudos: 275
My Contributions
Well, in the A* pathfinding algorithm u have an Open list that should be empty at the end. So they arent there and i only need the parents at the end when the open list is empty
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Class Containing Itself
1 Apr, 2008 - 04:12 AM
Post #6

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,042



Thanked: 106 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
QUOTE(manhaeve5 @ 1 Apr, 2008 - 07:40 AM) *

Well, in the A* pathfinding algorithm u have an Open list that should be empty at the end. So they arent there and i only need the parents at the end when the open list is empty


How do you know it's empty?

User is offlineProfile CardPM
+Quote Post

Pontus
RE: Class Containing Itself
1 Apr, 2008 - 05:20 AM
Post #7

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 530



Thanked: 2 times
Dream Kudos: 275
My Contributions
I dont but i know the parents arent in there anymore, if you dont know the algorithm its in fact all the same
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Class Containing Itself
1 Apr, 2008 - 06:19 AM
Post #8

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,042



Thanked: 106 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
QUOTE(manhaeve5 @ 1 Apr, 2008 - 09:20 AM) *

I dont but i know the parents arent in there anymore, if you dont know the algorithm its in fact all the same


The algorithm is irrelevant. If your parents disappear, you have a memory leak. If you intentionally removed them but neglectied to tell the affected nodes, you have a logic problem. If nothing is pointing to a node anymore, you have memory leak. Such design can't be blamed on an algorithm, only the implementation.

I would recommend reading up on how a linked list works or, if you're using C++, use one of the object template types to do the dirty work.

Good luck.

User is offlineProfile CardPM
+Quote Post

Pontus
RE: Class Containing Itself
1 Apr, 2008 - 06:58 AM
Post #9

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 530



Thanked: 2 times
Dream Kudos: 275
My Contributions
K, ty. Gonna drop it because it stopped working and i cant find why.
Thanks anyway
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:08PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month