passing ‘const IntBag’ as ‘this’ argument discards qualifiers [-fpermissive]
This is my code: '''C++ **
> int IntBag::operator[](int index){ //get array item
> return array_[index];
> }
>
> IntBag::IntBag (const IntBag& a){ //copy constructr
> size=a.getSize();
> for(int i=0; i<size; i++){
> int val=a[i];
> array_[i]=val;
> }
> }
>
> int IntBag::getSize()const{ //get the size of the array
> return size;
> }
>
> IntBag& IntBag::operator = (const IntBag& a){
> for(int i= 0; i< a.getSize(); i++) {
> array_[i]=a[i];
> }
> }
**
My error is: $ g++ intbag.cpp intbag.cpp: In copy constructor ‘IntBag::IntBag(const IntBag&)’: intbag.cpp:19:16: error: passing ‘const IntBag’ as ‘this’ argument discards qualifiers [-fpermissive] 19 | int val=a[i]; | ^ intbag.cpp:12:5: note: in call to ‘int IntBag::operator’ 12 | int IntBag::operator[](int index){ //get array item | ^~~~~~ intbag.cpp: In member function ‘IntBag& IntBag::operator=(const IntBag&)’: intbag.cpp:30:18: error: passing ‘const IntBag’ as ‘this’ argument discards qualifiers [-fpermissive] 30 | array_[i]=a[i]; | ^ intbag.cpp:12:5: note: in call to ‘int IntBag::operator’ 12 | int IntBag::operator[](int index){ //get array item | ^~~~~~ intbag.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type] 31 | } +++ |+ return *this; 32 | } | ^