In my header file:
Esame();
Esame(string);
Esame(string, Voto);
This is a c++ tester class:
//OK
Esame esame("Algoritmi e strutture dati", 30);
esame.stampaEsame();
//OK
Esame esame2("Metodi Avanzati di Programmazione");
esame2.setVoto(26);
esame2.stampaEsame();
//ERROR
Esame esame3();
esame3.setVoto(26); //Method could not be resolved
esame3.stampaEsame(); //Method could not be resolved
The code doesn’t compile at all. Why it doesn’t find the method if the object has been created with the same class in the code above?
esame3()does’nt call a default constructor. In your case the compiler is thinking that you have declared a methodIt should be
Esame esame3;OR
Esame esame3=Esame();Using
newto create an object would create an object that would be allocated dynamically..In that case your class would have to be a
pointerlike thisEsame *esame3=new Esame;You would have to use
->instead of.to access member method or variables..