D
Dhirendra Singh
Hi,
The following C++ program is not compiling on my system.
#include <iostream>
using namespace std;
class complex {
double re, im;
public:
complex( ) :re(0), im(0) {}
complex( double r ) :re(r), im(0) {}
complex( double r, double i) :re(r), im(i) {}
complex& operator=( complex& );
};
complex& complex:
perator=( complex& b )
{
re = b.re;
im = b.im;
return *this;
}
int main()
{
complex a ;
a = 3; // Gives compilation error. Not able to convert from scalar
3 to complex(3).
a = complex(3); // this is perfectly ok.
return 0;
}
I am using visual C++ compiler.
I am not able to figure out if there is something wrong with the
concept or compiler is stupid ?
The following C++ program is not compiling on my system.
#include <iostream>
using namespace std;
class complex {
double re, im;
public:
complex( ) :re(0), im(0) {}
complex( double r ) :re(r), im(0) {}
complex( double r, double i) :re(r), im(i) {}
complex& operator=( complex& );
};
complex& complex:
{
re = b.re;
im = b.im;
return *this;
}
int main()
{
complex a ;
a = 3; // Gives compilation error. Not able to convert from scalar
3 to complex(3).
a = complex(3); // this is perfectly ok.
return 0;
}
I am using visual C++ compiler.
I am not able to figure out if there is something wrong with the
concept or compiler is stupid ?