c++

11월 6일 class 내부 함수

송시혁 2013. 11. 6. 23:12
#include <iostream>
using namespace std;

int Score=10;

   class IntSample
   {
     public:// 공개, 무조건 접근이 가능하다.
          //void ShowScore();
        void ShowScore()//class 내무에 함수를 만들었다. 
         {
          int Score=200;// 함수에서의 선언.
           cout <<"점수 = " << Score << endl  ;//200이 출력.
           cout <<"점수 = " << IntSample::Score << endl; //intSample::에 의해서 class 내부에 있는 아래 
         //아래 int Score class 멤버가 실행된다. main()함수에서 100을 넣으므로 100이 출력된다.
           cout <<"점수 = " << ::Score << endl;// 스코프 연산자만 사용하는 경우 전역변수 int Score가 해당한다.10 출력.
          }
 
         int Score;

};
/*void IntSample::ShowScore()
{
cout <<"점수 = " << Score << endl;

}*/


int main()
{
   IntSample obj;

  obj.Score=100; //class멤버 Score에 100을 대입.
  obj.ShowScore();// 함수를 호출

  return 0;
}