No error is shown while running, but the output comes like this
f1=6.72623e-044
f2=0
f3=6.72623e-044
When I intialize by a=5, A warning comes like non-static data member initializers only available with -std c plus plus. And the output becomes f1=5 f2=5 f3=10
#include<iostream>
#include<cstdio>
using namespace std;
class FLOAT
{
float a;
public:
FLOAT(){}
FLOAT(float x)
{
x=a;
}
FLOAT operator +(FLOAT f);
void display(void);
};
FLOAT FLOAT::operator +(FLOAT f)
{
FLOAT t;
t.a=a+f.a;
return t;
}
void FLOAT::display(void)
{
cout<<a<<endl;
}
int main()
{
FLOAT f1,f2,f3;
f1=FLOAT(3.6);
f2=FLOAT(5.8);
f3=f1+f2;
cout<<"f1="; f1.display();
cout<<"f2="; f2.display();
cout<<"f3="; f3.display();
return 0;
}