메뉴 바로가기 검색 및 카테고리 바로가기

한빛미디어

뇌를 자극하는 C++ 프로그래밍

뇌를 자극하는 C++ 프로그래밍 질의응답 게시판입니다.

const, static 사용시 문제점 발생

2009-11-05

|

by

2310

주석부분 자세히 설명 부탁 드립니다.
안정적으로 하기 위해 한것 같은데 설명 부탁 드립니다.


#include
using std::endl;
using std::cout;

#include
using std::string;

class gradebook
{
public:
        const static int students = 10;  // 에러 발생 이유?? 그리고 const static 사용 이유??
        gradebook(string, const int []);  // const로 하는 이유??
        void setname(string);
        string getname();
        void disp();
private:
        string name;
        int grades[students]; // 에러 발생 이유??
};

gradebook::gradebook(string sname, const int gra[])
{
        setname(sname);

        for(int i=0; i                 grades[i] = gra[i];
}

void gradebook::setname(string sname)
{
        name = sname;
}

string gradebook::getname()
{
        return name;
}

void gradebook::disp()
{
        cout<
        for(int i=0; i         {
                cout<         }
        cout< }


void main()
{
        int grade[grade::students] = {10,30,40,60,39,60,80,100,35,76}; // grade::students 사용한 이유??

        gradebook g("kor", grade);

        g.disp();
}
댓글 입력