1 Replies - 229 Views - Last Post: 24 March 2012 - 08:22 PM Rate Topic: -----

#1 va12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-March 12

Operator Overloading

Posted 24 March 2012 - 07:37 PM

I'm getting errors where it says its not being declared in the scope. I'm having trouble also understanding this concept as well. Declare and implement the += operator overloading in the .h first file and .cxx second file.

class ComplexShape: public Shape {

        public:
                ComplexShape();
                void draw();
                virtual ~ComplexShape();
                ComplexShape & operator+=(Shape *);
};




#include <iostream>
#include "shape.h"
#include "complexshape.h"

ComplexShape::ComplexShape() : Shape(false){}

void ComplexShape::draw(){
        std::vector<Shape*> components = explodeShape();
        for (unsigned int i=0; i<components.size(); i++){
                components[i]->draw();
        }
}

ComplexShape::~ComplexShape(){
        std::cout << "ComplexShape::~ComplexShape()" << std::endl;
}

ComplexShape & ComplexShape::operator+=(Shape *rhs){
        std::vector<Shape*> components = rhs->explodeShape();
        for (unsigned int i=0; i<components.size(); i++){
                addShape(components[i]);
        }
        return *this;
                                                            

}

ComplexShape & ComplexShape::operator+=(Shape *rhs){
        std::vector<Shape*> components = rhs->explodeShape();
        for (unsigned int i=0; i<components.size(); i++){
                addShape(components[i]);
        }
        return *this;
}

ComplexShape & operator+=(ComplexShape &op1, Shape *op2){
        std::vector<Shape*> components = rhs->explodeShape();
        for (unsigned int i=0; i<components.size(); i++){
                addShape(components[i]);
        }
        return *this;

}



Is This A Good Question/Topic? 0
  • +

Replies To: Operator Overloading

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Operator Overloading

Posted 24 March 2012 - 08:22 PM

I don't think anybody can answer your first question because we don't know what "it" is. Post the complete error message, including all information about which file was being compiled and which line of code generated the error.

And it's also not clear what your confusion is regarding

Quote

I'm having trouble also understanding this concept as well. Declare and implement the += operator overloading in the .h first file and .cxx second file.
since you seem to have done that already.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1