728x90

클래스(Class)

- 사용자 정의 타임(Type)이다

- 변수와 함수로 이뤄져 있다.

- 멤버(member)

- class 키워드

- class를 선언하면 객체(object)가 된다.

- struct는 C++에서는 class이다.

 

class 형식

 class 클래서명

{

     멤버 리스트(변수와 함수)

};

 

class 사용 예

 

1. 멤버 변수 

#include <iostream>
using namespace std;

 

class smart

{

   int X;

   int Y;

};

2. 멤버 함수 

 #include <iostream>
using namespace std;

class smart
{
   int X;
   int Y;

   void Print()
   {
        cout<<X<<'\t'<<Y<<endl; 
   }
};

3. 멤버 함수 를 분리하는 예 -> 클래스 내용이 방대 해 질때 :: 스코프 연산사를 사용 함수를 분리 하는 방법

 #include <iostream>
using namespace std;

class smart
{
   int X;
   int Y;

};

void smart::Print()  // 스코프 연산자를 사용해서 함수의 소속을 구분하여 선언
   {
        cout<<X<<'\t'<<Y<<endl; 
   }

 ♣ class 선언(객체 생성) 

- class가 선언되었을 때 객체라고 한다.

- class는 사용자 정의 타입이므로 일반 변수

   또는 포인터 선언과 같은 형식을 사용한다.

 #include <iostream>
using namespace std;

class smart
{
   int X;
   int Y;

};

void smart::Print()  // 스코프 연산자를 사용해서 함수의 소속을 구분하여 선언
   {
        cout<<X<<'\t'<<Y<<endl; 
   }

 

int main()

{

 

}

 

 

 

 

'…™업무일지。 > …™C++。' 카테고리의 다른 글

※함수인자 디폴트  (0) 2014.10.15
※ 함수 오버로딩  (0) 2014.10.15
4강 메모리 할당과 해제  (0) 2014.10.12
입출력 namespace :: 스코프 연산자  (0) 2014.10.12
C++ 언어의 데이터형과 변수  (0) 2014.10.11