7.26(목) C++ 기초문법 - static 멤버

from Study/C++ 2007/07/28 23:53 view 16973

// 1. static 멤버data의특징: 모든객체가공유. 객체가없어도메모리에있다.

// 2. static 멤버함수의특징객체가없어도호출가능.

// 3. static 멤버에서는static 멤버만접근가능.

class Point

{

        int x;

        static int y;

 

public:

        void foo()

        {

               x = 10  // 1

               y = 10; // 2

        }

        static void goo()

        {

               cout << this << endl;  // error

               foo();  // error

               x = 10; // error

               y = 10; // 4

        }

};

 

int Point::y = 0;

 

void main()

{


        //클래스 내의 static 멤버 호출 시 1번으로 한다.
       
Point::goo();  // 1
일반함수인지static 함수인지를알수있다.

 

        Point p;

        p.goo();      // 2

}

 

Tag |

Trackback Address :: 이 글에는 트랙백을 보낼 수 없습니다