472,143 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

Simple Tree Syntax Error

I'm creating a real simple tree. No sorting and every node can have
infinite children.

// TreeNode.h

#ifndef TREENODE_H
#define TREENODE_H

#include <iostream>
#include <iomanip>
using namespace std;

// forward declare the tree class
template< class NODE_TYPE class Tree;

// template definition of tree node
template< class NODE_TYPE >
class TreeNode
{
// be friends with the tree class
friend class Tree< NODE_TYPE >;

private:
typedef TreeNode<NODE_TYPENode;
// can have infinite children
std::vector<intchildren;

NODE_TYPE data;

public:
// constructor
TreeNode( const NODE_TYPE &d ) : data(d)
{
// allocate memory for children nodes
//children = new std::vector<TreeNode< NODE_TYPE *>;
}

// accessor
NODE_TYPE getData() const
{
return data;
}
};

#endif

That is the declaration for my tree node. G++ keeps saying
std::vector<intchildren; has a syntax error. Sure enough if I
comment the line out, everything compiles. I'm going nuts though
trying to figoure out the error, I dont see it.

Help!

Jun 26 '07 #1
4 1783
Travis wrote:
I'm creating a real simple tree. No sorting and every node can have
infinite children.

// TreeNode.h

#ifndef TREENODE_H
#define TREENODE_H

#include <iostream>
#include <iomanip>
That is the declaration for my tree node. G++ keeps saying
std::vector<intchildren; has a syntax error. Sure enough if I
comment the line out, everything compiles. I'm going nuts though
trying to figoure out the error, I dont see it.
#include <vector>

Brian
Jun 26 '07 #2
Travis wrote:
I'm creating a real simple tree. No sorting and every node can have
infinite children.

// TreeNode.h

#ifndef TREENODE_H
#define TREENODE_H

#include <iostream>
#include <iomanip>
using namespace std;

// forward declare the tree class
template< class NODE_TYPE class Tree;

// template definition of tree node
template< class NODE_TYPE >
class TreeNode
{
// be friends with the tree class
friend class Tree< NODE_TYPE >;

private:
typedef TreeNode<NODE_TYPENode;
Right now, you are within the template TreeNode. Thus, the identifier
TreeNode already is a shorthand for TreeNode<NODE_TYPE>. There is no need
to abbreviate that any further.

// can have infinite children
std::vector<intchildren;
Don't you mean:

std::vector< TreeNode* children;
>
NODE_TYPE data;

public:
// constructor
TreeNode( const NODE_TYPE &d ) : data(d)
{
// allocate memory for children nodes
//children = new std::vector<TreeNode< NODE_TYPE *>;
Now this is going to be the trick part.
}

// accessor
NODE_TYPE getData() const
{
return data;
}
};

#endif

That is the declaration for my tree node. G++ keeps saying
std::vector<intchildren; has a syntax error. Sure enough if I
comment the line out, everything compiles. I'm going nuts though
trying to figoure out the error, I dont see it.
What is a vector of integers supposed to do for you?

Best

Kai-Uwe Bux
Jun 26 '07 #3
On Jun 26, 12:12 pm, "Default User" <defaultuse...@yahoo.comwrote:
Travis wrote:
I'm creating a real simple tree. No sorting and every node can have
infinite children.
// TreeNode.h
#ifndef TREENODE_H
#define TREENODE_H
#include <iostream>
#include <iomanip>
That is the declaration for my tree node. G++ keeps saying
std::vector<intchildren; has a syntax error. Sure enough if I
comment the line out, everything compiles. I'm going nuts though
trying to figoure out the error, I dont see it.

#include <vector>

Brian
Thank you! Too tired today. I appreciate it!

Jun 26 '07 #4
On Jun 26, 12:15 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Travis wrote:
I'm creating a real simple tree. No sorting and every node can have
infinite children.
// TreeNode.h
#ifndef TREENODE_H
#define TREENODE_H
#include <iostream>
#include <iomanip>
using namespace std;
// forward declare the tree class
template< class NODE_TYPE class Tree;
// template definition of tree node
template< class NODE_TYPE >
class TreeNode
{
// be friends with the tree class
friend class Tree< NODE_TYPE >;
private:
typedef TreeNode<NODE_TYPENode;

Right now, you are within the template TreeNode. Thus, the identifier
TreeNode already is a shorthand for TreeNode<NODE_TYPE>. There is no need
to abbreviate that any further.
// can have infinite children
std::vector<intchildren;

Don't you mean:

std::vector< TreeNode* children;
NODE_TYPE data;
public:
// constructor
TreeNode( const NODE_TYPE &d ) : data(d)
{
// allocate memory for children nodes
//children = new std::vector<TreeNode< NODE_TYPE *>;

Now this is going to be the trick part.
}
// accessor
NODE_TYPE getData() const
{
return data;
}
};
#endif
That is the declaration for my tree node. G++ keeps saying
std::vector<intchildren; has a syntax error. Sure enough if I
comment the line out, everything compiles. I'm going nuts though
trying to figoure out the error, I dont see it.

What is a vector of integers supposed to do for you?

Best

Kai-Uwe Bux
I switched it to INTs to make sure it wasn't a problem with me using
TreeNode< NODE_TYPE *>. I just forgot to change it back before
pasting it here. Thank you though.

Jun 26 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Terry | last post: by
4 posts views Thread by (Pete Cresswell) | last post: by
6 posts views Thread by sathyashrayan | last post: by
15 posts views Thread by Foodbank | last post: by
7 posts views Thread by (Jamie Andrews) | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.