I just don't understand why I get this error when I compile this single file main.cpp
#include <iostream>
#include <string>
class Hola{
private:
std::string saludo;
public:
Hola();
void salut();
};
Hola::Hola(){}
void Hola::salut(){
std::cout << "El string es " << saludo << std::endl;
}
int main{
Hola greet;
greet.salut();
}
And the compiling error when I type g++ -std=c++11 -o main main.cpp in the console is:
main.cpp:19:7: error: expected primary-expression before ‘greet’
Hola greet;
^
main.cpp:19:7: error: expected ‘}’ before ‘greet’
main.cpp:19:7: error: expected ‘,’ or ‘;’ before ‘greet’
main.cpp:20:2: error: ‘greet’ does not name a type
greet.salut();
^
main.cpp:21:1: error: expected declaration before ‘}’ token
}
^
For whoever that asks, I made this simple program because I didn't understand another one much larger and tried to simplify so I get what's wrong.
Aucun commentaire:
Enregistrer un commentaire