What will the program print out?
#include <iostream>
using namespace std;

class a {
private:
    virtual void f(int) { cout<<"a int"; }
};

class b : public a {
public:
    class a; friend
    void f(double) { cout<<"b double"; }
    void f(int) { cout<<"b int"; }
};

int main (void) {
  b* o = new b;
  o->f(0.5);
  return 0;
}
Explanation
In class b, the friend directive refers to f(double), i.e. it is a friendly function (not a class member), although defined in the class.
In main() there is a call to o->f(), i.e. the function that is the member of the class b, i.e. the function b::f(int).

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes