0
Code:
Header:
class Cliente
{
public:
Cliente(std::string nome_c, int num_cartao_l, int livros_c);
Cliente();
void calc_Taxa();
const int get_livros() const { return livros; }
const std::string get_nome() const { return nome; }
const int get_cartao() const { return num_cartao; }
const double get_taxa() const { return taxa; }
private:
int livros;
std::string nome;
int num_cartao; // numero do cartão do cliente
double taxa;
};
void const cliente_divida();
Cpp:
Cliente::Cliente(string nome_c, int num_cartao_l, int livros_c)
:nome(nome_c), num_cartao(num_cartao_l), livros(livros_c)
{
if (livros < 0) cout << "Livros não podem ser negativos, por favor reinicie o programa." << endl;
}
Cliente default_cliente()
{
Cliente def("Fulano", 000, 0);
return def;
}
Cliente::Cliente()
:nome(default_cliente().nome),
num_cartao(default_cliente().num_cartao),
livros(default_cliente().livros)
{
}
void Cliente::calc_Taxa()
{
taxa = livros * 4; // a taxa é de 4 dólares/reais
}
const void cliente_divida()
{
if (Cliente::get_taxa() == 0)
{
cout << "Cliente não possui dividas." << endl;
}
else cout << "Cliente possui uma divida de" << Cliente::get_taxa() << " dolares." << endl;
}
I don’t have anything on main yet.
Finally, the doubt is in const void cliente_divida()
, I cannot call the class member without first having declared an object, but in case I need to use the exact rate of the current main object. That would be work for a pointer or some method static
that would allow me to call the member without instantiating the object. I tried to transform the function get_taxa()
in static
and the taxa
in static
also but I received a unresolved external symbol
. I would like to know a clean method for the resolution.
NOTE: For better interpretation, consider that it is a program for library clients.
Maybe it would be interesting for the
main()
, theget_ taxa()
, better show what you want, ie make a [mcve].– Maniero
What you mean by: "but in case I need to use the exact rate of the current object of the main."? Anyway, how do you know the client is in debt if you don’t want to instantiate it? Because that’s what the command
Cliente::get_taxa()
you say– user5299
Opa, I solved instantiating an object in the function with the pointer
&
, theget_taxa()
was literally just that and minemain()
was an empty main scope. Anyway, thank you.– Marv
const void
I’ve never seen it before?– Kahler