|
그냥 그대로 복사해서 하나로 합쳐서 해보니 실행은 잘 됩니다.
보이는 코드로는 알 수 없어 보이는 군요.
의도하신바를 알진 못하지만 뭔가 좀 고치는게 나아보이는 부분 몇개 살포시~
Point3D 에서 Point2D 를 알아야 할 이유가 없다면
#include "Point.h" 로 바꾸는게 나아보이네요.
Point 클래스 입니다.
상속을 받아가며, 같은 이름의 함수를 넣는데 반환형이 다르면 무슨 소용이겠습니까.
int 형의 가상함수로 바꿔봤습니다.
class Point
{
public:
Point( int = 1, int = 2 );
virtual int GetArea() ;
protected:
int x ;
int y ;
};
다음은 생성자입니다.
Point2D 는 부모생성자와 달라보이지 않아 저렇게 바꾸었고,
Point3D 는 z 값만 설정이 되면, 부모생성자가 호출이 되어 전혀 다른 값이 들어갑니다.
Point3D와 Point의 생성자에서 xx, yy 값을 다르게 하고 보시면 알게되실겁니다.
Point2D::Point2D( int xx, int yy )
:Point( xx, yy )
{
}
Point3D::Point3D(int xx, int yy, int zz )
:Point( xx, yy )
{
z = zz ;
}
아 그런데 원인파악을 못했네요.
파일을 직접 올려보시지요~
그럼 빠를텐데요.
홍순규 님이 쓰신 글 :
: c++로 한건데...
:
: 문제는 이거고요..
:
: 기본 클래스 Point는 추상 클래스로 GetArea()를 멤버로 가지고 있다.
: 이것을 상속하여 int x, y 좌표와 GetArea()를 가지고 있는
: Point2D 클래스와 int x, y, z 좌표와 GetArea()를 가지고 있는 Point3D 클래스를 정의한다.
: GetArea()는 원점을 기준으로 사각형 면적과 육면체 부피를 계산하여 출력한다.
: 두 클래스 모두 x, y, z를 1, 2, 3으로 초기화하는 생성자를 만든다.
: main()에서는 Point 클래스 객체 포인터를 이용하여 면적과 부피를 출력한다.
:
: point.cpp파일이고요
:
: #include <iostream>
:
: using namespace std ;
:
: #include "point.h"
:
: Point::Point(int xx, int yy )
: {
: x = xx ;
: y = yy ;
: }
:
:
: void Point::GetArea()
: {
: return ;
: }
:
:
: point2D.cpp파일이고요
:
: #include "point2D.h"
:
: using namespace std ;
:
: Point2D::Point2D( int xx, int yy )
: {
: x = xx ;
: y = yy ;
: }
:
: int Point2D::GetArea()
: {
: return x * y ;
: }
:
: point3D.cpp파일이고요
:
: #include <iostream>
: #include "point3D.h"
:
: using namespace std ;
:
: Point3D::Point3D(int xx, int yy, int zz )
: {
: z = zz ;
: }
:
: int Point3D::GetArea()
: {
: return x * y * z ;
: }
:
: test.cpp 파일이고요!
: #include <iostream>
:
: #include "point3D.h"
:
: using namespace std ;
:
: int main()
: {
: Point3D p3;
:
: //printf("면적 or 부피 : %d\n", p3.GetArea() );
: cout<< "면적 아니면 부피 :" <<"\n";
:
: return 0;
: }
:
:
: point.h파일
:
: #include <iostream>
:
: class Point
: {
: public:
: Point( int = 1, int = 2 );
:
: void GetArea() ;
:
: protected:
: int x ;
: int y ;
:
: };
:
: point2D.h 파일
:
: #include "point.h"
:
: class Point2D: public Point
: {
: public :
: Point2D(int = 1 , int = 2) ;
:
: int GetArea();
: };
:
:
: point3D.h파일!
:
: #include "point2D.h"
:
: class Point3D: public Point
: {
: public :
: Point3D(int = 1, int = 2, int = 3);
:
: int GetArea();
:
: protected :
: int z;
: };
:
:
: 이렇게 파일을 나눠서 만들고 합쳐서 했는데
: 실행이 안되네요..
: 왜그런지요?^^
: 마무리좀 도와주세요~~~
|