3 / 3 / 2
Регистрация: 21.02.2015
Сообщений: 77
1

Underfined refference to .(все члены класса)

16.06.2016, 23:54. Показов 411. Ответов 1
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Есть класс:
list.h :
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef LIST_H
#define LIST_H
 
const char nullptr = 0;
 
template <class Data>
struct ListItem
    {
        Data item;
        ListItem *next;
        ListItem() {}
        ListItem(Data _item, ListItem *n = nullptr) { item = _item; next = n; }
    };
 
template <class Data>
class list
{
    unsigned int count;
    ListItem<Data> *first;
    ListItem<Data> *last;
public:
    list();
    list (const list &src);
    ~list();
    int head();
    int tail();
    void add(Data _item);
    void addFirst(Data _item);
    void addFirst(const list &src);
    void addLast(Data _item);
    void addLast(const list &src);
    ListItem<Data> *search(Data _key);
    unsigned int size() const;
    void removeFirst();
    void removeLast();
 
};
 
#endif
list.cpp :
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "list.h"
 
template <class Data>
list<Data>::list()
{
    count = 0;
    first = last = nullptr;
}
 
template <class Data>
list<Data>::list(const list &src)
{
 
}
 
template <class Data>
list<Data>::~list()
{
    ListItem<Data> *current = nullptr;
    ListItem<Data> *next = first;
    while (next != nullptr)
    {
        current = next;
        next = next->next;
        delete current;
    }
}
 
template <class Data>
int list<Data>::head()
{
    return first->item;
}
 
template <class Data>
int list<Data>::tail()
{
    return last->item;
}
 
template <class Data>
void list<Data>::add(Data _item)
{
    addLast(_item);
}
 
template <class Data>
void list<Data>::addFirst(Data _item)
{
    ListItem<Data> *p = new ListItem<Data>(_item, first);
    if (first == nullptr)
    {
        last = p;
    }
    first = p;
    count++;
}
 
template <class Data>
void list<Data>::addFirst(const list &src)
{
 
}
 
template <class Data>
void list<Data>::addLast(Data _item)
{
    ListItem<Data> *p = new ListItem<Data>(_item);
    if (last == nullptr)
    {
        first = p;
    }
    else
    {
        last->next = p;
    }
    last = p;
    count++;
}
 
template <class Data>
void  list<Data>::addLast(const list &src)
{
 
}
 
template <class Data>
ListItem<Data> *list<Data>::search(Data _key)
{
    ListItem<Data> *find = first;
    while (find != nullptr)
    {
        if (find->item == _key)
        {
            break;
        }
        find = find->next;
    }
    return find;
}
 
template <class Data>
unsigned int list<Data>::size() const
{
    return count;
}
 
template <class Data>
void list<Data>::removeFirst()
{
    ListItem<Data> *newFirst = first->next;
    delete first;
    first = newFirst;
    count--;
}
 
template <class Data>
void list<Data>::removeLast()
{
    ListItem<Data> *current = first;
    while (current->next != last)
    {
        current = current->next;
    }
    delete last;
    last = current;
    last->next = nullptr;
    count--;
}
main.cpp :
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include "list.h"
using namespace std;
int main()
{
    list<int> l;
    l.add(1);
    l.add(2);
    l.add(3);
    l.add(4);
    l.add(5);
    cout << "size=" << l.size() << endl;
    cout << "head=" << l.head() << endl;
    cout << "tail=" << l.tail() << endl;
    return 0;
}
И что же я получаю?
D:\Proj_directory\project1_cpp.o In function `main':
6 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::list()'
7 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::add(int)'
8 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::add(int)'
9 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::add(int)'
10 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::add(int)'
11 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::add(int)'
12 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::size() const'
13 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::head()'
14 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::tail()'
15 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::~list()'
15 D:\Proj_directory\project1_cpp.cpp undefined reference to `list<int>::~list()'
Что тут не так?
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
16.06.2016, 23:54
Ответы с готовыми решениями:

класс «Строка» (данные-члены класса – строчка, функции-члены класса – операции)
Помогите пожалйуста с реализацией программы... Реализовать класс «Строка» (данные-члены класса –...

Скрыть все наследуемые члены класса
public class Temp: List&lt;example&gt; { public void Method() { base.Add(new...

Стоит ли делать все методы и переменные-члены класса list статическими
Сделал класс list(знаю, что существует уже этот stl контейнер, просто сделал для себя), стоит ли...

Переставить члены последовательности так, чтобы сначала расположились все ее неотрицательные члены
Помогите решить задачу! :cofee2: Дана очередь, элементами которой являются действительные числа....

1
1181 / 894 / 94
Регистрация: 03.08.2011
Сообщений: 2,461
17.06.2016, 00:07 2
Не так то, что нельзя выносить реализацию шаблонов в отельную единицу трансляции. Верните все в .h файл.
1
17.06.2016, 00:07
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
17.06.2016, 00:07
Помогаю со студенческими работами здесь

Переставить члены последовательности так, чтобы сначала расположились все ее неотрицательные члены
Помогите пожалуйста решить задачу!!! Экзамен горит.... Выручайте!!! Дана очередь, элементами...

Наследование от protected класса: будут ли public члены класса Б доступны классу А
Добрый день! Если пронаследовать public класс А от protected класса Б, будут ли public члены...

Использовать private члены класса внутри static ф-ий этого же класса.
Все привет! Такая вот проблема. Есть класс (естественно тестовый, для пример): class SCRIPT{ ...

Underfined variable
есть файл 1.php: //некий код $a=&quot;qwe&quot;; include '1.html'; и есть файл 1.html, вызывающийся...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru