Advertisement

Overloaded operator crashing MSVC?

Started by September 15, 2000 08:07 AM
2 comments, last by Anthracks 24 years, 3 months ago
I''m trying to make a small vector class, and for some reason I cannot understand, the overloaded + operator is crashing MSVC. Not just the program but the IDE! I forget how to do one of those code boxes, but I''m gonna try now

class CVector
{
friend CVector operator+ (CVector& vec1, CVector& vec2)
	{
		CVector temp;
		
		temp.x=vec1.x + vec2.x;
		temp.y=vec1.y + vec2.y;
		temp.z=vec1.z + vec2.z;

		return temp;

	}

public:
	CVector();
	virtual ~CVector();

	long x;
	long y;
	long z;
};
 
The constructor and destructor are empty, and the main body of the program just declares two vectors, sets their coordinates and adds them together. Does anyone know what the heck is wrong with this? Thanks! Anthracks
The problem must be something else, that code you posted works fine (after removing the ctor & dtor declaration). If it''s not to long, you should post the other part of the program that you use the vector in.
Advertisement
Sure, here''s the main body:

    #include "main.h"void main(){	CVector back;	CVector off;	back.x=2;	back.y=3;	back.z=4;	off.x=6;	off.y=7;	off.z=8;	back=back+off;	//cout << back.x << "," << back.y << "," << back.z << ".\n\n";		return;}    



the main.h file just has iostream.h and that class definition.

Thanks again

Anthracks
It works fine for me. Although strictly speaking main should return int and not void, but MSVC doesn''t mind either way.

What version are you using? Have you tried installing the latest service pack?

This topic is closed to new replies.

Advertisement