#include <iostream>
struct B ;
struct A
{
A( int i ) : v(i) {}
private : int v ;
friendintoperator+ ( const A& a, const B& b ) ;
};
struct B
{
B( int i ) : v(i*i) {}
private : int v ;
friendintoperator+ ( const A& a, const B& b ) ;
};
inlineintoperator+ ( const A& a, const B& b ) { return a.v + b.v ; }
//inline int operator+ ( const B& b, const A& a ) { return a+b ; }
int main()
{
A seven(7) ;
B sixteen(4) ;
std::cout << seven+sixteen << '\n' ; // 23
}
#include <iostream>
class Common
{
int member;
friendvoid Foo(Common& input);
};
class A : public Common {};
class B : public Common {};
void Foo (Common& input)
{
std::cout << input.member;
}
int main()
{
A a;
B b;
Foo (a);
Foo (b);
return 0;
}
#include <iostream>
class Common
{
public:
Common(int i) : member(i) {}
protected:
int member;
friend std::ostream& operator<<(std::ostream& o, Common& rhs);
};
class A : public Common { public: A() : Common(1) {}};
class B : public Common { public: B() : Common(2) {}};
std::ostream& operator<<(std::ostream& o, Common& rhs)
{
o << rhs.member;
return o;
}
int main()
{
A a;
B b;
std::cout << a;
std::cout << b;
return 0;
}