Visual C++ .NET/Class/Access Modifier
Public, Protected and Private Methods
#include "stdafx.h"
using namespace System;
ref class MethodEx
{
public:
void printPublic(int num)
{
for (int i = 0; i < num; i++)
{
Console::WriteLine( "Public" );
}
printProtected(num/2);
}
protected:
void printProtected(int num)
{
for (int i = 0; i < num; i++)
{
Console::WriteLine( "Protected" );
}
printPrivate(num/2);
}
private:
void printPrivate(int num)
{
for (int i = 0; i < num; i++)
{
Console::WriteLine( "Private" );
}
}
};
int main()
{
MethodEx ex;
ex.printPublic(4);
}
Specify Member Access
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
class MyClass {
private:
int x;
public:
int y;
};
int main(void) {
MyClass inst;
inst.x = 10;
}