I must develop a program implementing classes and objects which in the end returns a name, the problem is that I do not understand what you mean when you say that I have not declared the variable "name" if it is, in the private section
C:\Users\Usuario\Desktop\Programación c++\Ejercicio basico [1] construc\main.cpp|19|error: 'nombre' was not declared in this scope|
This is the program
#include <iostream>
using namespace std;
class Persona {
private:
string nombre;
public:
Persona(string _nombre);
string getNombre();
};
Persona::Persona(string _nombre){
nombre = _nombre;
}
string getNombre(){
return nombre;
}
int main (){
Persona persona1("Andres");
cout<<persona1.getNombre();
return 0;
}
You forgot to include the
Persona::
before the name of your functiongetNombre()