An object has type classifiers that are not compatible with a member function.

#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; } 

in no.set (area, local); states that "the object has type classifiers that are not compatible with the member function"

what should I do??

+6
source share
3 answers

You pass no as const , but you are trying to change 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; } 
+8
source

Your set method is not const (and should not be), but you are trying to call it on a const object.

Extract const from parameter in operator >> :

 istream& operator>>(istream& is, PhoneNumber& no) 
+6
source

In the operator → there is a second parameter with the type const PhoneNumber & not, that it is a constant object, but you are trying to change it using a set of member functions. For const objects, you can only call member functions that have the const qualifier.

+2
source

Source: https://habr.com/ru/post/958960/


All Articles