Неопределенная ссылка G++ на class::function [дубликат]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Неопределенная ссылка G++ на class::function [дубликат]

Сообщение Anonymous »

Я наконец-то в отчаянии. Итак, на моем уроке по C++ нас попросили использовать классы. У нас будет заголовочный файл, объявляющий класс и функции, а отдельный файл .cpp реализует его. Все должно работать, но это не так, и никакие решения в Интернете, похоже, мне не помогают. Для этого я использую компилятор G++ для Linux, и он, похоже, не работает ни в IDE, ни в обычной командной строке.

В моем TBook.h появляется следующая ошибка:

Код: Выделить всё

/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/tmp/ccxqI6An.o: In function `TBook::TBook()':
TBook.cpp:(.text+0x3b): undefined reference to `Telephone::Telephone()'
TBook.cpp:(.text+0x100): undefined reference to `Telephone::Telephone()'
TBook.cpp:(.text+0x132): undefined reference to `Telephone::allNum(std::basic_string)'
TBook.cpp:(.text+0x182): undefined reference to `Telephone::~Telephone()'
TBook.cpp:(.text+0x191): undefined reference to `Telephone::~Telephone()'
TBook.cpp:(.text+0x2b3): undefined reference to `Telephone::~Telephone()'
TBook.cpp:(.text+0x2e6): undefined reference to `Telephone::~Telephone()'
TBook.cpp:(.text+0x2fa): undefined reference to `Telephone::~Telephone()'
/tmp/ccxqI6An.o:TBook.cpp:(.text+0x370): more undefined references to `Telephone::~Telephone()' follow
/tmp/ccxqI6An.o: In function `TBook::write()':
TBook.cpp:(.text+0x4e1): undefined reference to `Telephone::getNumber()'
TBook.cpp:(.text+0x506): undefined reference to `Telephone::getAreaCode()'
TBook.cpp:(.text+0x53a): undefined reference to `Telephone::getName()'
/tmp/ccxqI6An.o: In function `TBook::lookup(std::basic_string)':
TBook.cpp:(.text+0x6d4): undefined reference to `Telephone::getName()'
TBook.cpp:(.text+0x79e): undefined reference to `Telephone::Telephone(int, std::basic_string, std::basic_string)'
/tmp/ccxqI6An.o: In function `TBook::print()':
TBook.cpp:(.text+0x880): undefined reference to `Telephone::getName()'
TBook.cpp:(.text+0x8e0): undefined reference to `Telephone::getNumber()'
TBook.cpp:(.text+0x8ff): undefined reference to `Telephone::getAreaCode()'
collect2: ld returned 1 exit status
[Finished in 0.3s with exit code 1]
Мне не нравится, что файл не получает ни одного метода класса Телефон. Вот как выглядит код для TBook.h:

Код: Выделить всё

#ifndef TBOOK_H
#define TBOOK_H

#include "Telephone.h"

class TBook{
private:
Telephone rolodex[10];
int current;
int max;
public:
TBook();
~TBook();
void add(Telephone);
void write();
bool is_full();
void print();
void check();
Telephone lookup(string);

};

#endif
А вот как выглядит TBook.cpp:

Код: Выделить всё

#include 
#include 
#include 

#include "TBook.h"
#include "Telephone.h"

using namespace std;

TBook::TBook(){
current = 0;
max = 9;

cout 

Подробнее здесь: [url]https://stackoverflow.com/questions/19661406/g-undefined-reference-to-classfunction[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»