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).

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести