Reputation: 470
#include<iostream>
using namespace std;
class PhoneNumber
{
int areacode;
int localnum;
public:
PhoneNumber();
PhoneNumber(const int, const int);
void display() const;
bool valid() const;
void set(int, int);
PhoneNumber& operator=(const PhoneNumber& no);
PhoneNumber(const PhoneNumber&);
};
istream& operator>>(istream& is, const PhoneNumber& no);
istream& operator>>(istream& is, const PhoneNumber& no)
{
int area, local;
cout << "Area Code : ";
is >> area;
cout << "Local number : ";
is >> local;
no.set(area, local);
return is;
}
at no.set(area, local); it says that "the object has type qualifiers that are not compatible with the member function"
what should i do...?
Upvotes: 15
Views: 48703
Reputation: 310920
In the operator >> there is the second parameter with type const PhoneNumber& no that is it is a constant object, But you are trying to change it using member function set. For const objects you may call only member functions that have qualifier const.
Upvotes: 3
Reputation:
You're passing no
as const
, but you try to modify it.
istream& operator>>(istream& is, const PhoneNumber& no)
//-------------------------------^
{
int area, local;
cout << "Area Code : ";
is >> area;
cout << "Local number : ";
is >> local;
no.set(area, local); // <------
return is;
}
Upvotes: 17
Reputation: 258548
Your set
method is not const
(nor should it be), but you're attempting to call it on a const
object.
Remove the const
from the parameter to operator >>
:
istream& operator>>(istream& is, PhoneNumber& no)
Upvotes: 11