Problem after reorganization

Hi ,

I transformed my program in a modular program becahse all was in one header.
But now there is a problem I don't know ..

1
2
3
4
5
6
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


main.cpp
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include "Vehicule.h"


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


Vehicule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#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();
}


Vehicule.cpp
1
2
3
4
5
6
7
8
9
10
11
#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
1
2
3
4
5
6
7
8
#include <iostream>
#include "Vehicule.h"

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


CreateurConcretRenault.cpp
1
2
3
4
5
6
#include "CreateurConcretRenault.h"

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


CreateurConcretFiat.h
1
2
3
4
5
6
7
8
#include <iostream>
#include "Vehicule.h"

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


CreateurConcretFiat.h
1
2
3
4
5
6
#include "CreateurConcretFiat.h"

std::string CreateurConcretFiat::getMarque() const
{
    return "Fiat";
}
Last edited on
Topic archived. No new replies allowed.