mercredi 22 décembre 2021

About func(const int&) and func(const int)

#include <iostream>

class Account {
public:
    static double GetCircumference(const double &dR) { return 2 * dR * 3.1415926; }
    static constexpr double cd = 3.0;
};

// constexpr double Account::cd;

int main()
{
    std::cout << Account::GetCircumference(Account::cd) << std::endl;
}

The code is wrong unless I remove the "//". But if I only change (const double &dR) to (const double dR), it becomes ok too. Why?

Aucun commentaire:

Enregistrer un commentaire