C++ 6.접근 지정자

-접근 지정자

//Student.h

#pragma once

#include <string>

using namespace std;

 

#define DEF_IQ 100 //디폴트 IQ

#define MAX_IQ 300 //최대 IQ

 

class Student

{

        int num;

        string name;

        int iq;

 

public:

        Student(int _num, string _name);

        void Study(int hour);

        void View();

};

 

 

//Student.cpp

#include "Student.h"

#include <iostream>

using namespace std;

 

Student::Student(int _num, string _name)

{

        num = _num;

        name = _name;

        iq = DEF_IQ;

}

 

void Student::Study(int hour)

{

        cout<<name<<"학생"<<hour<<"시간 공부하다."<<endl;

}

 

void Student::View()

{

        cout<<"번호:"<<num<<", 이름:"<<name<<", 아이큐 "<<iq<<endl;

}

 

 

//Program.cpp

 

#include "Student.h"

 

int main(void)

{

        Student stu(34,"홍길동");

        stu.View();

        stu.Study(50);

        stu.View();

        //stu.iq + = 300; //private 접근 지정한 멤버는 형식 외부에서는 접근 .

        stu.View();

 

        return 0;

}

 

728x90

'C++ > 설명' 카테고리의 다른 글

C++ 9.복사 생성자  (0) 2016.04.19
C++ 7.생성자와 소멸자  (0) 2016.04.19
C++ 5.정적 클래스  (0) 2016.04.19
C++ 4.정적멤버 static  (0) 2016.04.19
C++ 3. 특별한 멤버 this  (0) 2016.04.19

이 글을 공유하기

댓글

Designed by JB FACTORY