0

我将我的程序转换为模块化程序,因为所有内容都在一个标题中。但是现在有一个问题我不知道..

Undefined symbols for architecture x86_64:
"Vehicule::createVehicule(std::string)", referenced from:
   _main in main-aV2PNG.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1

主文件

#include <iostream>
#include "Vehicule.h"

int main()
{
Vehicule *v=Vehicule::createVehicule("fr");
presenter(v);
return 0;
}

车辆.h

#include <iostream>

class Vehicule
{
public:
virtual std::string getMarque() const =0;
friend std::ostream &operator<<(std::ostream &o,const Vehicule *v);
static Vehicule* createVehicule(std::string origine);
};

void presenter(const Vehicule *v)
{
std::cout << "Vehicule " << v << std::endl;
}

std::ostream &operator<<(std::ostream &o,const Vehicule *v)
{
return o << v->getMarque();
}

车辆.cpp

#include "Vehicule.h"
#include "CreateurConcretRenault.h"
#include "CreateurConcretFiat.h"

Vehicule* Vehicule::createVehicule(std::string origine)
{
if(origine=="fr") return new CreateurConcretRenault();
else if(origine=="ita") return new CreateurConcretFiat();

else return new CreateurConcretRenault();
}

CreateurConcretRenault.h

#include <iostream>
#include "Vehicule.h"

class CreateurConcretRenault : public Vehicule
{
public:
std::string getMarque() const;
};

CreateurConcretRenault.cpp

#include "CreateurConcretRenault.h"

std::string CreateurConcretRenault::getMarque() const
{
return "Renault";
}

CreateurConcretFiat.h

#include <iostream>
#include "Vehicule.h"

class CreateurConcretFiat : public Vehicule
{
public:
std::string getMarque() const;
};

CreateurConcretFiat.cpp

#include "CreateurConcretFiat.h"

std::string CreateurConcretFiat::getMarque() const
{
return "Fiat";
}
4

2 回答 2

0

我试图将所有内容放在一个标题中并且它有效..

所以我以为我忘记了什么

于 2013-07-27T19:23:47.023 回答
0

您正在使用std::string,但您从未包含<string>

于 2013-07-27T19:06:46.060 回答