Visibility of private field of a template class from a template function

  access-modifiers, c++, class, templates

I have a template class

template<class T>
class MyClass
{
public:
    MyClass() { privateField = 0; };
    T getPrivateField() {
        return privateField;
    }
private:
    T privateField;
};

and a template function which takes an instance of MyClass as a parameter

template<class T>
T foo(MyClass<T> mc) {
    return mc.privateField;
}

I was confused by the fact that I can see a private field of MyClass in template function, but can’t actually use it.
Here is an example of field visibility(screenshot)
Question:
Why can I see a private field of MyClass exactly in a template function and how can I disable it in my code(if it’s possible)? Or it’s just like a feature from Visual Studio?

Source: Windows Questions C++

LEAVE A COMMENT