S
Steven T. Hatton
In the following code, at what point is S::c fully defined?
#include <iostream>
using std::cout;
using std::endl;
using std:stream;
class C {
int _v;
public:
C(const int& v)
:_v(v)
{}
ostream& print(ostream& out) const
{
return out << _v;
}
};
struct S {
static const C c;
};
const C S::c = C(42);
ostream& operator<<(ostream& out, const S& s)
{
s.c.print(out);
return out;
}
int main()
{
S s;
cout << s << endl;
return 0;
}
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
#include <iostream>
using std::cout;
using std::endl;
using std:stream;
class C {
int _v;
public:
C(const int& v)
:_v(v)
{}
ostream& print(ostream& out) const
{
return out << _v;
}
};
struct S {
static const C c;
};
const C S::c = C(42);
ostream& operator<<(ostream& out, const S& s)
{
s.c.print(out);
return out;
}
int main()
{
S s;
cout << s << endl;
return 0;
}
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell