Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!enuxha!hocker From: hocker@enuxha.eas.asu.edu (Charles C. Hocker) Newsgroups: comp.lang.c++ Subject: overloading operator+ Keywords: Overloading Message-ID: <1742@enuxha.eas.asu.edu> Date: 10 Nov 90 00:41:27 GMT Organization: Arizona State University, Tempe, AZ Lines: 46 Hello, I am new to c++ and am having a problem trying to overload the operator+. What I am trying to do, is I have a structure and I want to add structures together. struct p { int X, Y, Z; }; class pclass { public: p pnt; pclass (int x, int y, int z); }; pclass::pclass (int x=0, int y=0, int z=0) { pnt.X = x; pnt.Y = y; pnt.Z = z; } pclass operator+ (p a, p b) { return p (a.X+b.X, a.Y+b.Y, a.Z+b.Z); } int main (void) { pclass p1 (1, 2, 3), p2 (2, 3, 4), p3; p3 = p1 + p2; } When compiling this program in TC++, I receive an errors concerning the overloading of the operator+. I am writing a graphics program and I would like to add points without having to add their respective values. This, by the way, is my first attempt with c++ so I am not quite sure what I am doing. I have referenced both the TC++ manual, and the ARM. Sincerly Charles C. Hocker hocker@enuxha.eas.asu.edu