what does this static const is meant to be doing ?
The code is working now, but what happens 'f1 = Fraction::sc_fUnity ;' is called. Why in the implementation 'const Fraction::Fraction sc_fUnity(1,1);' the
body of the function is missing ?
> Why in the implementation 'const Fraction::Fraction sc_fUnity(1,1);'
> the body of the function is missing ?
Because it is not a static member function; it is a static member variable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
struct A
{
staticint foo() ; // declaration of static member function
staticconstint bar ; // declaration of static member variable
};
int A::foo() { return 1 ; } // definition of static member function
constint A::bar(2) ; // definition of static member variable
int main()
{
std::cout << A::foo() << ' ' // call function A::foo()
<< A::bar << '\n' ; // A::bar is not a function; there is no function call
}