Expected unqualified-id ')' token

I'm trying to build a binary search tree for a class and I'm getting the error,
"Expected unqualified-id before ')' token" at my ,"class Node()". I don't understand on
what is wrong with it.

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

class Node()
{
public:
Node<int,int,int,string,string,string>(int times,int flight,int gate,string airline,string city,string status)
{
this-> times = times;
this-> flight = flight;
this-> gate = gate;
this-> airline = airline;
this-> city = city;
this-> status = status;
left = NULL;
right = NULL;
parent = NULL;
}
Node *left;
Node *right;
Node *parent;
};
Last edited on
class Node()
Remove the parentheses.
Last edited on
Several things wrong.

Line 5. () don't belong on your class declaration.
Line 8. Why are you using template notation <> here? Are you trying to define a nested class or a constructor?
Lines 10-15: You're trying to store variables into members of the class, but you have no such member variables.

Try this instead:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
using namespace std;

class Node
{   int m_times;      //  Added member variables
    int m_flight;
    int m_gate; 
    string m_airline;
    string m_city;
    string m_status;
public:
    Node *left;
    Node *right;
    Node *parent;
    // Changed to a constructor
    Node(int times,int flight,int gate,string airline,string city,string status)
    {   m_times = times;
        m_flight = flight;
        m_gate = gate;
        m_airline = airline;
        m_city = city;
        m_status = status;
        left = NULL;
        right = NULL;
        parent = NULL;
    }
};


Note: It's poor style to name your arguments and member variables the same thing. I changed the member variables to use the m_ prefix to indicate they're member variables. THis eliminates any ambiguity.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Last edited on
Topic archived. No new replies allowed.