Lyprandos Liatsos
Lyprandos Liatsos

Reputation: 25

error: expected unqualified-id before ‘friend’

In my .cpp file I got

Student:: friend istream& operator>>(istream &input,Student &a){
       input>>a.AM>>a.name>>a.semester>>;
       return input;
   }

And in my .h file I got

friend istream &operator>>(istream &input,Student &a);

I keep getting that error and I don't know what to do.Any help?

Upvotes: 1

Views: 137

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 310990

Rewrite the definition like

istream& operator>>(istream &input,Student &a){
   input>>a.AM>>a.name>>a.semester>>;
   return input;
}

The specifier friend is used only in a declaration of a friend function within a class.

And a friend function is not a member of the class granting friendship.

Upvotes: 1

Related Questions