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
Зареєструйся Зараз
або Підпишись на майбутні тести