본문 바로가기

프로그래밍/C++

private 변수값 초기화 하기


함수에서
classprivate 변수인 a의 값 50이 출력되도록 프로그램하세요.

main()

{

CMy me;

cout << me.a << endl; // 50 출력

}





#include "stdafx.h"
#include <iostream>
using namespace std;
class CMy
{
private:
 int a;
public:
 CMy(){a=50;}
 friend void main();
};

void main()
{
 CMy me;
 me.a;
 cout << me.a << endl;
}