473,372 Members | 825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 1903
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
4
by: (Pete Cresswell) | last post by:
I'm getting nodes into the thing, but when the dust settles, only the root-level nodes are visible. I know they're there because .Nodes.Count gives the right number.\ But I don't really...
6
by: sathyashrayan | last post by:
#include<stdio.h> #include<stdlib.h> #include<string.h> struct tree { int data; struct tree *left,*right; }; void init(struct tree *node)
15
by: Foodbank | last post by:
Hi all, I'm trying to do a binary search and collect some stats from a text file in order to compare the processing times of this program (binary searching) versus an old program using linked...
7
by: (Jamie Andrews) | last post by:
For a research project, we're looking for a reliable parser for C that will take an ANSI C program and yield a tree representation of the program (as a Java or C++ object). Of course a grammar...
1
by: forrie | last post by:
We're running multiple vhosts in an apache-2.x configuration for which we would like to provide separate php.ini files (for different reasons). At the moment, we're unable to do this - the error...
1
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template...
2
by: gasfusion | last post by:
Hey guys. I'm currently taking a course where everyone in the class will code a compiler for a simple C-like language. I'm doing mine in C# and have some general questions for efficiency and the...
6
kenobewan
by: kenobewan | last post by:
Congratulations! You are one of the few who realise that over 80% of errors are simple and easy to fix. It is important to realise this as it can save a lot of time. Time that could be wasted making...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.