Please tell what I am doing wrong in this code below, compilor is giving me following error 1. declaration of operator = as non function 2. expected primary expression before const I am not able to identify my mistake
and so on plz help me
#include <iostream>
using namespace std;
class myClass{
int a;
int b;
public:
myClass();
myClass(int x, int y);
const myClass& operator=(const myClass &);
void display();
};
myClass::myClass(){
a=0;
b=0;
}
myClass::myClass(int x, int y){
this->a=x;
this->b=y;
}
const myClass& myClass::operator=(const class & rightobj){
if(this!=&rightobj){
this->a=rightobj.a;
this->b=rightobj.b;
}
return *this;
}
void myClass::display(){
cout<<a<<endl;
cout<<b<<endl;
}
int main(){
myClass class1(2,3);
myClass class2;
class2=class1;
class2.display();
return 0;
}