소스에 함수의 원형과 정의가 없는 것이 문제가 아니었습니다. 있었으니까요. 소스를 안보셨군요.
멤버함수의 반환형이 문제였습니다. 클래스 객체로 접근해야 하는 것도 있지요.
theRect.DrawShape() 이렇게 말이지요.
반환형이 void일 때는 theRect가 Illegal structure(부정한 구조)라고 메세지가 나옵니다.
void가 아니어야 합니다.
Intotheblue 님이 쓰신 글 :
: 함수 부분을 이해를 못하신거네요...
: 사실 에러 메세지에 설명이 다 나와 있는건데..
:
: 책에서..
: 함수 부분에서 프로토 타입 or 함수 원형에 대해서 찾아보세요..
:
: c장군 님이 쓰신 글 :
: : 소스는 인포북에 있는 것이고요. 그런데, 컴파일러는 에러메세지를 냅니다.
: : 소스는 다음과 같습니다.
: : #include <iostream.h>
: : typedef unsigned short int USHORT;
: :
: : class Rectangle
: : {
: : public:
: : Rectangle(USHORT width , USHORT height);
: : ~Rectangle(){}
: :
: : void DrawShape() const;
: : void DrawShape(USHORT width , USHORT height) const;
: :
: : private:
: : USHORT Width;
: : USHORT Height;
: : };
: :
: : Rectangle::Rectangle(USHORT width , USHORT height)
: : {
: : Width = width;
: : Height = height;
: : }
: :
: : void Rectangle::DrawShape() const
: : {
: : DrawShape(Width , Height);
: : }
: :
: : void Rectangle::DrawShape(USHORT width , USHORT height) const
: : {
: : for(USHORT i=0 ; i<height ; i++)
: : {
: : for(USHORT j=0 ; j<width ; j++)
: : {
: : cout << "*";
: : }
: : cout << "\n";
: : }
: : }
: :
: : void main()
: : {
: : Rectangle theRect(30,5);
: :
: : cout << "DrawShape()\n" << DrawShape() << endl;
: :
: : cout << "\nDrawShape(40,2)\n" << DrawShape(40,2) << endl;
: : }
: : 에서 컴파일 에러메세지는
: : Error : Function "DrawShape" should have a prototype.
: : 이라고 출력됩니다.
: : 어디서 무엇이 문제인지 좀 어렵네요.
|