473,789 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_T YPENode;
// can have infinite children
std::vector<int children;

NODE_TYPE data;

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

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

#endif

That is the declaration for my tree node. G++ keeps saying
std::vector<int children; 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 1929
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<int children; 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_T YPENode;
Right now, you are within the template TreeNode. Thus, the identifier
TreeNode already is a shorthand for TreeNode<NODE_T YPE>. There is no need
to abbreviate that any further.

// can have infinite children
std::vector<int children;
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<Tre eNode< 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<int children; 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<int children; 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_T YPENode;

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

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<Tre eNode< 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<int children; 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
2908
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 loaded into cache, the slideshow doesn't look very nice. I am not sure how/when to call the slideshow() function to make sure it starts after the preload has been completed.
4
1886
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 understand the significance of the Nodes.Add syntax - I'm just slavishly plugging in values. Viz: ---------------------------
6
3670
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
5100
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 lists. I'm totally new to binary searches by the way. Can anyone help me with the commented sections below? Much of the code such as functions and printfs has already been completed. Any help is greatly appreciated. Thanks,
7
5690
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 e.g. in jflex/jbison that will yield the same thing is fine too. We have been able to find some grammars and parsers, of unknown reliability, that don't yield a syntax tree; we want to avoid starting with a flaky parser and/or adding the syntax...
1
8530
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 I'm seeing is: Starting httpd: Syntax error on line 87 of /etc/httpd/conf/vhost.conf.admin: Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored
1
2952
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 <typename Tclass Tree{ private: Tree<T*left;
2
1971
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 actual architecture. I've coded a lexer which reads code and categorizes everything into groups. I'm using a hash table to store all of the lexems, where the key to the table is the order of appearance of a lexem in the code and the value is the type...
6
28873
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 unnecessary changes, that in turn can cause further problems. Programming is a humbling experience. An experience that causes one to reflect on human error. One major cause of these errors is syntax, syntax, syntax. We tend not to notice when we...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.