What lines have errors when compiling this code?
#include <iostream>

using namespace std;

class Test
{
public:
    bool flag;
    Test () { flag = false; }
    static int ObjectCount; // 1
    static void POut () // 2
    {
        cout << flag; // 3
        cout << ObjectCount; // 4
    }
};

int Test::ObjectCount = 0; // 5

int main ()
{
    Test T;
}
Explanation
In static function members, it's not possible to access non-static class data members directly. Everything is tied to this pointer. If non-static member functions of a class receive this pointer implicitly, then static member functions of the class do not receive it, since static data members are used by all instances of this class.

Follow CodeGalaxy

Mobile Beta

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