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
Overloaded operator crashing MSVC?
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
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.
Sure, here''s the main body:
the main.h file just has iostream.h and that class definition.
Thanks again
Anthracks
#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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement