Quantcast
Channel: C2679 with classes
Viewing all articles
Browse latest Browse all 4

C2679 with classes

$
0
0

I have condensed my three-file project as much as I can to ask my question. Here is the code:

FOO2.h:

class FOO2
{
public:
	FOO2( double x, double y ) { _X = x, _Y = y; }
	FOO2( double x ) { _X = x, _Y = 0.0 ;}
    FOO2() { _X = 0.0, _Y = 0.0; }
	double _X;
	double _Y;
	FOO2 &operator=( FOO2 & );
    FOO2 &operator=( double & );
	FOO2 TestFOO(void);
};
extern FOO2 * pFOO;


FOO2.cpp:

#include "stdafx.h"
#include "FOO2.h"

FOO2 &FOO2::operator=( double &RHS_double )
{
   _X = RHS_double;
   _Y = 0.0;
   return *this;  // '=' returns left side.
};

FOO2 &FOO2::operator=(FOO2 &RHS_FOO2 )
{
   _X = RHS_FOO2._X;
   _Y = RHS_FOO2._Y;
   return *this;  // '=' returns left side.
};

double xxx, yyy;
FOO2 fff = FOO2();

FOO2 FOO2::TestFOO()
{
	xxx = 256.0;
	yyy = -1.0;
	fff = xxx;
	//fff = xxx + yyy;		//C2679
	return fff;
}

driver.cpp:

#include "stdafx.h"
#include "FOO2.h"

FOO2 * pFOO = new FOO2();

int _tmain(int argc, _TCHAR* argv[])
{
	pFOO -> TestFOO();
	return 0;
}

My question is in FOO2.cpp, in the function TestFOO(). The first two lines assign values to the two doubles xxx and yyy. The third line shows that the overloaded operator =, defined earlier in the file, works in assigning a double to an FOO2 object. But the fourth line, when not commented out, produces C2679: binary '=': no operator found which takes a right-hand operand of type 'double'.Is not the expression xxx+yyy of type double? and did not the previous line show that an appropriate operator exists and was recognized by the compiler?

I've spend time trying to figure out this paradox but to no avail. I would appreciate some help!


gabriel weinreich


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images