#include <iostream>
using namespace std;
class X
{
int m_value;
public:
X(int val) : m_value(val) {}
friend ostream& operator<<(ostream& o, X& x) { return o << x.m_value; }
};
class Y
{
public:
Y(int val) { value(val); };
friend ostream& operator<<(ostream& o, Y& y) { return o << y.value(); }
private:
int value(int val=0) { static int value = val; return value; }
};
int main()
{
// Using membervariables
X a(8), b(68), c(3);
cout << a << ", " << b << ", " << c << endl;
//Using static int
Y d(22), e(45), f(87);
cout << d << ", " << e << ", "<< f << endl;
}
#include <iostream>
using namespace std;
class X
{
int m_value;
public:
X(int val) : m_value(val) {}
friend ostream& operator<<(ostream& o, X& x) { return o << x.m_value; }
};
class Y
{
public:
Y(int val) { value(val); };
friend ostream& operator<<(ostream& o, Y& y) { return o << y.value(); }
private:
int value(int val=0) { static int value = val; return value; }
};
int main()
{
// Using membervariables
X a(8), b(68), c(3);
cout << a << ", " << b << ", " << c << endl;
//Using static int
Y d(22), e(45), f(87);
cout << d << ", " << e << ", "<< f << endl;
}
To copy to clipboard, switch view to plain text mode
Bookmarks