Reputation: 11
So, I keep getting an error saying I need an unqualified-id and cant figure out what is giving me the error. please help.
the error occurs on the Node()
part of the class.
error: expected unqualified-id before ‘)’ token
Node()
^
Here's the code:
#include <iostream>
#include <string>
using namespace std;
class AHuffman
{
public:
class Node
{
Node* right_child;
Node* left_child;
Node* parent;
Node* sibling;
int weight;
int number;
string data;
};
Node()
{
right_child = NULL;
left_child = NULL;
parent = NULL;
sibling = NULL;
weight = 0
number = 1;
data = "";
}
// int encode(string* msg, char** result, int rbuff_size);
// int decode(string* msg, char** result, int rbuff_size);
AHuffman(string* alphabet);
~AHuffman();
};
int main(int argc, const char* argv[])
{
if(argc != 4){
//Invalid number of arguments
cout << "invalid number of arguments" << endl;
return 1;
}
string* alphabet = new string(argv[1]);
string* message = new string(argv[2]);
string* operation = new string(argv[3]);
return 0;
}
Upvotes: 1
Views: 997
Reputation: 586
Looks like a poorly copy pasted code. The 'Node constructor first should either have a declaration inside the 'Node' class or move the definition inside as below.
You decla
class Node
{
private: // private members
Node* right_child;
Node* left_child;
Node* parent;
Node* sibling;
int weight;
int number;
string data;
public: // make it public so the class can actually be constructible
Node()
{
right_child = NULL;
left_child = NULL;
parent = NULL;
sibling = NULL;
weight = 0; // and delimiter here
number = 1;
data = "";
}
};
Upvotes: 0
Reputation: 6016
Because you put the constructor of Node outside of its class:
Anyway, you should initialize its members in member initializer list instead of in constructor body.
class Node
{
Node* right_child;
Node* left_child;
Node* parent;
Node* sibling;
int weight;
int number;
string data;
public:
Node()
: right_child(0), left_child(0),
parent(0), sibling(0),
weight(0), number(1)
{
}
};
Another note, you don't need that much new
in C++
Upvotes: 4