Let's say we have 2 classes :
class base{
protected:
char first_name;
public:
/// constructors , destructor, operator= overloading ...
friend istream& operator >> (istream& in, base &client1)
{
char f_name[1001];
cout << "First Name: ";
in >> f_name;
client1=base(f_name); /// class parameterised constructor;
return in;
}
};
class derived: public base{
protected:
char last_name[1001];
public:
/// constructors , destructor, operator= overloading ...
friend istream& operator >> (istream& in, derived &client2)
{
char l_name[1001], f_name[1001];
in >> (base) client2; /// it's not working like it dose in operator<<..
cout << "Last Name: ";
is >> l_name;
client2=derived(f_name, l_name); /// class parameterized constructor, 2 parameters because it use base constructor as well;
return in;
}
};
I overloaded some output operators (<<) and it seems to do fine every time i call the operator<< from base in derived operator<<.
I don't know if this works the same for operator<<, i tried something but it gives an error. When i call base class operator>> inside derived class operator>> it gives me error :
" no matching function for call to 'operator>>(std::istream&, abonament)'| "
Again, if i do the same thing in operator<< , it's working fine :
friend ostream& operator << (ostream& out, derived &client)
{
out << (base) client; /// it's working;
out << client.last_name;
return in;
}
Is it possible to call base class operator>> inside derived class operator>> > Why is this happening and how to solve it ? ( i hope i don't have to rewrite the same lines from base class operator>> again in derived class operator>> )