For given nested classes in C++, what will be the output of the following code:
#include <iostream> 
using namespace std;

class A {
public:
    int a;
    int getB() {
        return B::b;
    }
    class B {
    public:
                B() {
            b = 1;
        }
        int b;
    };
};

int main() 
{
    A a;
    cout << a.getB();
    return 0;
}
Explanation
_Non-static_ class fields can only be accessed through a class instance.
In member function 'int A::getB()':
 error: invalid use of non-static data member 'A::B::b'
         return B::b;
                   ^

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты