When Float(const Integer&);
is declared, the Integer
class has been not declared yet.
This should work for what you want:
#include <iostream>
using namespace std;
class Integer;
class Float
{
float x, y;
public:
Float() : x(0),y(0) {}
Float(float a, float b) : x(a),y(b) {}
Float(const Integer&);
float getX() const { return this->x; }
float getY() const { return this->y; }
float summa()
{
return this->x + this->y;
}
};
class Integer
{
int v, w;
public:
Integer() : v(0),w(0) {}
Integer(int a, int b) : v(a),w(b) {}
Integer(const Float&);
int getV() const { return this->v; }
int getW() const { return this->w; }
int summa()
{
return this->v + this->w;
}
};
int main()
{
Integer i(5, 2);
Float f = i;
Float F(3.23, 5.78);
Integer I = F;
cout << f.summa();
cout << I.summa();
return 0;
}
Float::Float(const Integer& i)
{
this->x = (float)(i.getV());
this->y = (float)(i.getW());
}
Integer::Integer(const Float& f)
{
this->v = (int)(f.getX());
this->w = (int)(f.getY());
}
solved Problem converting one user-defined class to another user-defined class [closed]