benutzen Sie '&' zu erstellen, die einen Zeiger auf member-Fehler

Ich bin neu in c++. Ich mache ein tutorial Frage bezüglich der Vererbung. Ich habe diesen Fehler "'Box::getVolume': Nicht-standard-syntax; benutzen Sie '&' zu erstellen, die einen Zeiger auf member". Da bin ich relativ neu, ich verstehe nicht, was benötigt wird, um es zu beheben. Das ist mein code.

Rechteck.h

class Rectangle {
private:
   int length;
   int width;

public:
   Rectangle();
   void setR(int, int);
   int getLength();
   int getWidth();
   int getArea();
   void displayR();     
};

Rectangle.cpp

Rectangle::Rectangle(){}

void Rectangle::setR(int l, int w) {
    length = l;
    width = w;
}

int Rectangle::getLength() {
    return length;
}

int Rectangle::getWidth() {
    return width;
}

int Rectangle::getArea(){ 
    return length*width;
}

void Rectangle::displayR() {
    cout<<"Length: "<<getLength()<<endl;
    cout<<"Width: "<<getWidth()<<endl;
}

Box.h

class Box : public Rectangle {
private:
   int height;

public:
   Box();
   void setBox(int);
   int getHeight();
   int getVolume();
   void displayB();

};

Box.cpp

Box::Box(){ }

void Box::setBox(int h){
   height = h;
}

int Box::getHeight(){
   return height;
}

int Box::getVolume(){ 
   return getArea()*height;
}

void Box::displayB(){
   cout<<"Box height: "<<getHeight()<<endl;
   cout<<"Box volume: "<<getVolume()<<endl;
Woops, gar nicht sehen, dass...
das ist in Ordnung, es ist vererbt

InformationsquelleAutor ChewingSomething | 2015-09-18

Schreibe einen Kommentar