Whenever i try to run my program, it gives me an error saying that i'm missing an argument for the eight parameter in my constructor Here is the struct Here is the struct
struct maximos {
size_t lengthTitulo;
size_t lengthAutor;
size_t lengthIdioma;
size_t lengthGenero;
void CreacionVariables();
};
Here is the constructor
Libro(const std::string = "", const std::string = "", const std::string = "", int = 0, int = 0, const std::string = "", int = 0, maximos&);
i've tried writing "maximos& obj", but it doesn't work. other than that i don't know what to do.
Whenever i try to run my program, it gives me an error saying that i'm missing an argument for the eight parameter in my constructor Here is the struct Here is the struct
struct maximos {
size_t lengthTitulo;
size_t lengthAutor;
size_t lengthIdioma;
size_t lengthGenero;
void CreacionVariables();
};
Here is the constructor
Libro(const std::string = "", const std::string = "", const std::string = "", int = 0, int = 0, const std::string = "", int = 0, maximos&);
i've tried writing "maximos& obj", but it doesn't work. other than that i don't know what to do.
Share Improve this question edited Nov 17, 2024 at 3:50 John Kugelman 363k69 gold badges553 silver badges597 bronze badges asked Nov 17, 2024 at 3:45 Franco Zavala ManFranco Zavala Man 1 5 |1 Answer
Reset to default 4If you want to pass a default argument to the last parameter then declare it const:
Libro(const std::string = "", const std::string = "", const std::string = "", int = 0, int = 0, const std::string = "", int = 0, const maximos& = {});
You cannot make it non const because a non const reference can't bind rvalue, which is a default argument because it does not have a name.
If you strictly should pass a non const default argument, then overloaded functions/constructors are your friends.
Libro(const std::string, const std::string, const std::string, int, int, const std::string, int, maximos&);
Libro(const std::string a = "", const std::string b = "", const std::string c = "", int d = 0, int e = 0, const std::string f = "", int g = 0) {
maximos deafault_maximos;
Libro(a, b, c, d, e, f, g, deafault_maximos);
}
Libro
is not a constructor formaximos
– Ted Lyngmo Commented Nov 17, 2024 at 3:50