M
mimi
Hi,all.
The section 13.5.1 of the <C++ primer 3rd edition> says, a static
member frunction may not be declared as const or volatile. I could not
explain to myself why? The constness seems to be irrelevant to whether
the function is static or non-static.
Furthermore, i am not sure the following program is correct. According
to the book, it should be wrong, but my compiler says it is right.
class Account
{
public:
static const double interest() {return _interestRate;}
private:
static double _interestRate; //I know i should declared it as
const, but it is also OK.
};
double Account::_interestRate = 1;
int main()
{
Account::interest();
return 0;
}
The section 13.5.1 of the <C++ primer 3rd edition> says, a static
member frunction may not be declared as const or volatile. I could not
explain to myself why? The constness seems to be irrelevant to whether
the function is static or non-static.
Furthermore, i am not sure the following program is correct. According
to the book, it should be wrong, but my compiler says it is right.
class Account
{
public:
static const double interest() {return _interestRate;}
private:
static double _interestRate; //I know i should declared it as
const, but it is also OK.
};
double Account::_interestRate = 1;
int main()
{
Account::interest();
return 0;
}