[ create a new paste ] login | about

Link: http://codepad.org/O3gwlO7J    [ raw code | output | fork ]

C++, pasted on Nov 19:
#include <stdio.h>

struct TestStruct
{
    int value;

    TestStruct(int value, int prv)
        : value(value),
        _private(prv)
    {

    }

    int GetPrivate() const
    {
        return _private;
    }

private:
    int _private;

    int getPublic() const
    {
        return value;
    }
};

int main()
{
    TestStruct test(1, 3);
    printf("public: %d\n", test.value);
    printf("private: %d\n", test.GetPrivate());

    printf("public: %d\n", test.getPublic()); //Compile error C2248: Cannot access private member declared in class 'TestStruct'.
    printf("private: %d\n", test._private); //Compile error C2248: Cannot access private member declared in class 'TestStruct'.

    return 0;
}


Output:
1
2
3
In function 'int main()':
Line 22: error: 'int TestStruct::getPublic() const' is private
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: