Thread: operator overloading

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    operator overloading

    I have a vector class and I want to overload some operators for it, so I made the class like this:
    Code:
    class vec {
    public:
      float x, y;
      vec(float setx = 0, float sety = 0) {
        set(setx,sety);
      }
      vec(vec& rhs) {
        x = rhs.x;
        y = rhs.y;
      }
      vec operator=(vec& rhs) {
        x = rhs.x;
        y = rhs.y;
        return rhs;
      }
      vec operator+(vec& rhs) {
        vec ret(x+rhs.x,y+rhs.y);
        return ret;
      }
    };
    (with other stuff too) But when I try to compile this:
    Code:
      vec a, b, c;
      a = b + c;
    I get errors about that operator not existing like:
    7 C:\Dev-Cpp\antigrav\main.cpp no match for 'operator=' in 'a = vec::operator+(vec&)(((vec&)(&c)))'
    I was totally sure this was how to overload operators, but now I'm not so sure. What am I doing wrong?
    Last edited by ichijoji; 07-15-2005 at 03:24 PM.
    Illusion and reality become impartiality and confidence.

Popular pages Recent additions subscribe to a feed