473,322 Members | 1,614 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,322 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 1902
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.