I'm not sure what you're trying to achieve here as your code is hard to follow. For instance, max() does not count the maximum but sets a value based on two other values, and then prints this value. Normally, the parameter list would have been one, two, three, but for some reason, you chose a different order. You do not use constructors to initialize your classes, but rather use a set() method. Furthermore, you have three identical classes, they only differ in their names. Why not just have one?
Again, your logic is hard to follow.
I've "fixed" your code to compile and run:
#include <iostream>
#include <conio.h>
using namespace std;
class third;
class one;
class two
{
int a;
public:
void set (int i)
{
a = i;
}
friend void max(two, one, third);
};
class one
{
int b;
public:
void set(int i)
{
b = i;
}
friend void max(two, one, third);
};
class third
{
int c;
public:
void set(int i)
{
c = i;
}
friend void max(two, one, third);
};
void max(two x, one y, third z)
{
z.c = x.a + y.b;
cout << z.c;
}
int main()
{
one obj;
obj.set(100);
two obj1;
obj1.set(200);
third obj2;
max(obj1, obj, obj2);
return 0;
}
Here's a better solution to the problem. Use whatever you deem appropriate for your needs:
#include <iostream>
template<class T> class Number
{
private:
T _value;
public:
Number(T value) : _value(value) { }
friend T Sum<T>(const Number<T> & a, const Number<T> & b, const Number<T> & c);
};
template<class T> T Sum(const Number<T> & a, const Number<T> & b, const Number<T> & c)
{
return a._value + b._value + c._value;
}
int main()
{
Number<int> i1(100);
Number<int> i2(200);
Number<int> i3(300);
std::cout << Sum(i1, i2, i3) << std::endl;
Number<double> d1(0.1);
Number<double> d2(0.2);
Number<double> d3(0.3);
std::cout << Sum(d1, d2, d3) << std::endl;
return 0;
}