-1

まず、慌てないでください。これは非常に単純なプログラムです。「g++ -Wall -pedantic Main.cpp」を使用して Main.cpp をコンパイルすると、このエラーが発生します。ここにすべてのファイルがあります。エラーへの未定義参照の原因は何ですか?

メイン.cpp

#include <iostream>
#include "BMWLogo.h"
#include "Engine.h"
#include "IVehicle.h"
#include "Car.h"
#include "BMW.h"

int main() {
    BMW* bmw = new BMW();
    Car* car = bmw;
    std::cout << car->getName() << std::endl;
}

IVehicle.h

class IVehicle {
    public:
        IVehicle();
        virtual std::string getName();
        virtual float getCurrentSpeed();
};

IVehicle.cpp

#include "IVehicle.h"

IVehicle::IVehicle() {

}
virtual std::string IVehicle::getName() {

}
virtual float IVehicle::getCurrentSpeed() {

}

車.h

class Car : public IVehicle {

    private:
        std::string name;
        float currentSpeed;
        Engine* engine;
    public:
        Car(std::string name);

        void setCurrentSpeed(float currentSpeed);

        float getCurrentSpeed();

        std::string getName();

};

車.cpp

#include "Car.h"

Car::Car(std::string name) {
    this->name = name;
    engine = new Engine();
}

void Car::setCurrentSpeed(float currentSpeed) {
    this->currentSpeed = currentSpeed;
}

float Car::getCurrentSpeed() {
    return currentSpeed;
}

std::string Car::getName() {
    return name;
}

BMW.h

class BMW : public Car {
    private: 
        BMWLogo* bmwLogo;
    public:
        BMW();
};

BMW.cpp

#include "BMW.h"

BMW::BMW()
: Car("BMW") {
    bmwLogo = new BMWLogo();
}

エンジン.h

class Engine {

    Engine();

};

エンジン.cpp

#include "Engine.h"

Engine::Engine() {

}

BMWLogo.h

class BMWLogo {

    BMWLogo();

};

BMWロゴ.cpp

#include "BMWLogo.h"

BMLogo::BMWLogo() {

}
4

3 に答える 3

0

一見、Car.h で IVehicle.h を参照する必要があると思います。

#include "IVehicle.h"

于 2013-05-06T22:46:15.637 に答える
0

IVehicleコンストラクターの定義がありません。

于 2013-05-06T22:42:15.853 に答える