Visibility of Class Variables

I did not check it in the C++ standard, but as I understand it, variables, typedefs and functions are not only visible from the point of declaration, but within the entire class. So the following will compile:

class A {
public:
A() {
private_type var;
private_variable = 5;
private_function();
}

private:
typedef int private_type;
int private_variable;
void private_function();
};

Don’t use a private typedef within the parameter declaration of a public class, though. It may work, but it shouldn’t since whoever uses that function should also have the types of the parameters available.

Dieser Beitrag wurde unter C++ veröffentlicht. Setze ein Lesezeichen auf den Permalink.