Doubt about using static

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 do not own anything on main yet.

Anyway, the question is in const void cliente_divida() , I can not call the class member without first declaring an object, but in the case I need to use the exact rate of the current main object. That would be the work for a pointer or some static method that would allow me to call the member without instantiating the object. I tried to transform the function get_taxa() into static and taxa into static also but I got a unresolved external symbol . I would like to know a clean method for resolution.

NOTE: For best interpretation, consider it a program for library clients.

    
asked by anonymous 14.07.2016 / 20:11

1 answer

1

Your client_id function can be parameterized by a client instance, so another part of the code would be responsible for instantiating the client and calling the client_id function.

    
19.07.2016 / 13:47