Step 3 of 4
Constructor and methods
The constructor initializes the object. Methods define behavior (show, encrypt, etc.).
Your file so far
#include <iostream>
#include <string>
class Mensaje {
private:
std::string texto;
public:
Mensaje(const std::string& t) : texto(t) {}
void mostrar() const {
std::cout << texto << std::endl;
}
};
int main() {
Mensaje m("Hola desde POO");
m.mostrar();
return 0;
}
What you add in this step
public:
Mensaje(const std::string& t) : texto(t) {}
void mostrar() const {
std::cout << texto << std::endl;
}