제 문제는 클래스에 대해 많이 알지 못합니다. 그래서, 나는이 생성자를 작동 시키려고 노력하고있다. 기본 생성자와 파생 클래스의 생성자가 필요하므로 구현하지 않아도됩니다. 나는 그것을 정의 할 수있다. 나는 그것을 구현할 수 없다. 컴파일러가 중괄호를 기대하고 있다고 나에게 말하고있다. 나는 그것이 나에게주고 오류를 이해하지 못하는 SHAPE.H #ifdef와 SHAPE.H #DEFINE이 코드를 사용할 때 계속 오류가 발생합니다. 상속 된 클래스에서 생성자를 사용하려고합니다. C++
#include<string>
using namespace std;
class QuizShape
{
private:
char outer, inner;
string quizLabel;
public:
//Constructor
QuizShape();
};
class Rectangle : public QuizShape
{
public:
int height, width;
//Getter & setter methods
int getHeight() const;
void setHeight(int);
int getWidth() const;
void setWidth(int);
//Constructor for Rectangle
Rectangle() : QuizShape();
};
class Square : public Rectangle
{
public:
//constructors
Square() : Rectangle(); This area here is where the error comes // IT says it expects a { but I'm not allowed to define the constructor in line.
Square(int w, int h) : Rectangle (height , width);
};
class doubleSquare : public Square
{
//Fill in with constructors
};
#endif // 이는 . 나는 그것도 다시 정의하지 않을 것이라고 확신한다.
정말 고마워요. 그냥 호기심에서 벗어 났을 때 Square (int w, int h) : Rectangle (h, w) {} 그게 바로 정의 되나요? – varrick
대부분 환영합니다. 함수를 정의하는 것은 "{}"입니다 (빈 정의 임에도 불구하고). ": Rectangle (h, w)"를 호출하면 기본 클래스 Rectangle의 매개 변수화 된 생성자가 호출됩니다. – Arun
그럼, 다른 .cpp 파일에 여전히 구현할 수 있습니까? – varrick