Object creation error

I am a complete c++ noob. Start to learn it from the java. So, after hard study with some tutorials, I ended up with this class named Token:

#include "Token.h"
#include <iostream>
using namespace std;
//int Token::frequency = 0;



Token::Token() {
    // TODO Auto-generated constructor stub
    frequency=0;
    tok = "hey i am created";
    cout << tok << endl; // prints !!!Hello World!!!

}

Token::~Token() {
    // TODO Auto-generated destructor stub
}

The header for this class is this:

#ifndef TOKEN_H_
#define TOKEN_H_
#include <string>

class Token {
    std::string tok;
    int frequency;
public:
    Token();
    virtual ~Token();
};

#endif /* TOKEN_H_ */

It looks like in the tutorial, all right. The error is when I called it in my main class:

#ifndef TOKEN_H_
#define TOKEN_H_
#include <iostream>
using namespace std;

int main() {
    Token myToken;
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}
#endif /* TOKEN_H_ */

The error says :

Tokenizer.cpp:15:8: error: expected ‘;’ before ‘myToken’

Whyyy? I looked up the tutorials and answers here, it looks like I am doing it right? What is going on? And, if you see that I did some other crap, pls tell me, I will be thankful, I just came from Java to C++…


Source: oop

Leave a Reply