Здравствуйте. У меня есть следующий код main.cpp| Код | #include "dom.cpp" #include <iostream> //#include <vcl.h> using namespace std;
int main(int argc, char* argv[]) { Dom* doma[5]; doma[0] = new NeboSkreb(2,3); doma[1] = new Krepost(1,2); doma[2] = new Vila(2,5); doma[3] = new NeboSkreb(2,3); doma[4] = new Krepost(4,5);
for (int i = 0; i < 5; i++) { otpeciatatCenu(*doma[i]); otpeciatatCenu2(*doma[i]); }
return 0; }
|
dom.cpp| Код | #include <iostream> #include "dom.h" #define kaina 8
using namespace std;
void Dom::stroit() const { cout << "Dom::stroit()" << endl; }
int Dom::poscitatCenu() const { return plosad*kaina; }
void ZilojDom::stroit() const { cout << "ZilojDom::stroit()" << endl; }
void NeboSkreb::stroit() const { cout << "NeboSkreb::stroit()" << endl; }
int NeboSkreb::poscitatCenu() const { return plosad*visota*kaina; }
void Krepost::stroit() const { cout << "Krepost::stroit()" << endl; }
int Krepost::poscitatCenu() const { return plosad*plytusk*kaina; }
int Vila::poscitatCenu() const { return plosad*objem*kaina; }
void otpeciatatCenu(const Dom n) { cout << "Cena doma: " << n.poscitatCenu() << endl; return; }
void otpeciatatCenu2(const Dom &n) { cout << "Cena doma: " << n.poscitatCenu() << endl; return; }
|
dom.h| Код | #ifndef DOM_H #define DOM_H
class Dom { public: int plosad; virtual void stroit() const; virtual int poscitatCenu() const; };
class ZilojDom : public Dom { public: void stroit() const; };
class NeboSkreb : public Dom { private: int visota; public: NeboSkreb(int plosad_, int visota_){plosad = plosad_; visota = visota_;} void stroit() const; int poscitatCenu() const; };
class Krepost : public Dom { private: int plytusk; public: Krepost(int plosad_, int plytusk_){plosad = plosad_; plytusk = plytusk_;} void stroit() const; int poscitatCenu() const; };
class Vila : public ZilojDom { private: int objem; public: int poscitatCenu() const; Vila(int plosad_, int objem_){plosad = plosad_; objem = objem_;} };
void otpeciatatCenu(const Dom n); void otpeciatatCenu2(const Dom &n);
#endif
|
При попытке скомпилировать через g++ makefile| Код | prog: main.o dom.o g++ main.o dom.o -o prog
main.o: main.cpp dom.h g++ -c main.cpp
dom.o: dom.cpp dom.h g++ -c dom.cpp
clean: rm -f prog main.o dom.o
|
Получаю ошибку | Цитата | dom.o: In function `Dom::poscitatCenu() const': dom.cpp:(.text+0x0): multiple definition of `Dom::poscitatCenu() const' main.o:main.cpp:(.text+0x0): first defined here dom.o: In function `NeboSkreb::poscitatCenu() const': dom.cpp:(.text+0x14): multiple definition of `NeboSkreb::poscitatCenu() const' main.o:main.cpp:(.text+0x14): first defined here dom.o: In function `Krepost::poscitatCenu() const': dom.cpp:(.text+0x32): multiple definition of `Krepost::poscitatCenu() const' main.o:main.cpp:(.text+0x32): first defined here dom.o: In function `Vila::poscitatCenu() const': dom.cpp:(.text+0x50): multiple definition of `Vila::poscitatCenu() const' main.o:main.cpp:(.text+0x50): first defined here dom.o: In function `Krepost::stroit() const': dom.cpp:(.text+0x6e): multiple definition of `Krepost::stroit() const' main.o:main.cpp:(.text+0x6e): first defined here dom.o: In function `NeboSkreb::stroit() const': dom.cpp:(.text+0x98): multiple definition of `NeboSkreb::stroit() const' main.o:main.cpp:(.text+0x98): first defined here dom.o: In function `ZilojDom::stroit() const': dom.cpp:(.text+0xc2): multiple definition of `ZilojDom::stroit() const' main.o:main.cpp:(.text+0xc2): first defined here dom.o: In function `Dom::stroit() const': dom.cpp:(.text+0xec): multiple definition of `Dom::stroit() const' main.o:main.cpp:(.text+0xec): first defined here dom.o: In function `otpeciatatCenu2(Dom const&)': dom.cpp:(.text+0x168): multiple definition of `otpeciatatCenu2(Dom const&)' main.o:main.cpp:(.text+0x168): first defined here dom.o: In function `otpeciatatCenu(Dom)': dom.cpp:(.text+0x1b8): multiple definition of `otpeciatatCenu(Dom)' main.o:main.cpp:(.text+0x1b8): first defined here collect2: ld returned 1 exit status make: *** [prog] Error 1
|
Хотя до этого в CodeGear C++ всё компилировалось нормально. Подскажите пожалуйста, в чём тут может быть ощибка? Это сообщение отредактировал(а) Ak47black - 13.12.2009, 16:53
Присоединённый файл ( Кол-во скачиваний: 2 )
onServer.rar 1,11 Kb
|