Модераторы: bsa
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Не компилируется под g++ 
V
    Опции темы
Ak47black
  Дата 13.12.2009, 16:51 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 2205
Регистрация: 2.12.2005

Репутация: нет
Всего: 0



Здравствуйте.
У меня есть следующий код
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
PM MAIL   Вверх
586
Дата 13.12.2009, 16:56 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 2243
Регистрация: 8.5.2006

Репутация: 8
Всего: 146



Этог из-за того, что в main.cpp подключается файл "dom.cpp". Должны подключаться только .h-файлы.
PM   Вверх
Ak47black
Дата 13.12.2009, 17:00 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 2205
Регистрация: 2.12.2005

Репутация: нет
Всего: 0



О благодарю, за быструю помощь.
Не заметил такую малую неточность.
+
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "C/C++: Для новичков"
JackYF
bsa

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, JackYF, bsa.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C/C++: Для новичков | Следующая тема »


 




[ Время генерации скрипта: 0.0431 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.