divyang4481 / mipt-hw

Automatically exported from code.google.com/p/mipt-hw
0 stars 0 forks source link

task01 TVector (Яковенко) #180

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
iakovenko_pavel\TVector

Юлий Романович, только когда я меняю int на 
что-нибудь другое в векторе (шаблонный тип), 
у меня проблемы с статическими переменными 
Created и Deleted. ошибки возникают.

Original issue reported on code.google.com by iakovenk...@gmail.com on 26 Feb 2013 at 6:25

GoogleCodeExporter commented 9 years ago
Не совсем понял, в чем проблема.
В SVN это есть?

Original comment by aivyu...@gmail.com on 26 Feb 2013 at 6:34

GoogleCodeExporter commented 9 years ago
Да, в SVN все есть. Просто, когда я меняю в 
TVector<int> на TVector<float>  и соответственно меняю 
везде это, то он пишет "Неразрешенный 
внешний элемент", указывая на  Created и Deleted. И 
я не знаю, как это исправить. с int все 
прекрасно работает. Да и вообще, весь vector 
вроде в норме, все функции работают как и 
положено с любыми типами.

Original comment by iakovenk...@gmail.com on 27 Feb 2013 at 7:56

GoogleCodeExporter commented 9 years ago
Эта проблема еще актуальна? Или мы 
разобрались с ней на занятии?

Original comment by aivyu...@gmail.com on 8 Mar 2013 at 8:07

GoogleCodeExporter commented 9 years ago
0. Ошибки компиляции:
./main.cpp:295: error: too few template-parameter-lists
./main.cpp:296: error: too few template-parameter-lists
./main.cpp: In function ‘int main()’:
./main.cpp:322: error: no match for ‘operator!=’ in ‘pos != a. 
TVector<T>::end [with T = int]()’
./main.cpp:31: note: candidates are: bool 
TVector<T>::iterator::operator!=(TVector<T>::iterator&) [with T = int]
./main.cpp: In member function ‘void TVector<T>::erase(TVector<T>::iterator, 
TVector<T>::iterator) [with T = int]’:
./main.cpp:328:   instantiated from here
./main.cpp:238: warning: unused variable ‘p’

Собственно, мне казалось, мы разбирались с 
этим.
Нет смысла делать эти статические поля у 
vector. Смысл у них какой: посчитать кол-во 
созданий и удалений объектов, которые мы 
храним в векторе. Значит это должны быть 
статические поля у класса, объекты 
которого Вы складываете в вектор.

1. В задании указано название метод reserve, а 
не rehearsal.

2. Не имеет никакого смысла хранить beg, end, 
Begin, End в полях класса. Их вычисление - 
очевидно. К тому же это может быть 
потенциальной ошибкой. Ведь Вам необходимо 
в них всегда содержать актуальные значения.

3. show лучше сделать внешней функцией, чтобы 
не замусориваться интерфейс класса. В 
идеале Ваша задача - сделать библиотечный 
класс, которым должны пользоваться 
множество людей. Лишнее в интерфейсе 
связывает Вам руки. Т.к. если Вы захотите 
вдруг изменить интерфейс, то после 
обновления у людей перестанет собираться 
их код.

4. Где-то Вы работаете с итераторами, где-то - 
с указателями. Это плохой стиль. Более того, 
Вы включаете указатели в интерфейс методов 
класса - это уже противоречит условию 
задачи.

Original comment by aivyu...@gmail.com on 8 Mar 2013 at 8:17

GoogleCodeExporter commented 9 years ago
Как Вы думаете, а зачем вообще нужно 
реализовывать встроенный метод swap, если 
уже есть функция swap, выполняющая ту же 
функцию, что и Ваш метод, но для лубого типа?

К TList то же самое замечание.

Original comment by aivyu...@gmail.com on 8 Mar 2013 at 8:32

GoogleCodeExporter commented 9 years ago

Original comment by iakovenk...@gmail.com on 18 May 2013 at 7:47

GoogleCodeExporter commented 9 years ago
0. У меня куууча ошибок компиляции.

Пробую собирать с поддержкой С++11, получаю 
(g++ v4.7):
main.cpp: In member function 'void TVector<T>::resize(unsigned int)':
main.cpp:262:11: warning: suggest explicit braces to avoid ambiguous 'else' 
[-Wparentheses]
main.cpp: In function 'void show(TVector<T>&)':
main.cpp:356:3: error: need 'typename' before 'TVector<T>::const_iterator' 
because 'TVector<T>' is a dependent scope
main.cpp:356:33: error: expected ';' before 'pos'
main.cpp:357:17: error: 'pos' was not declared in this scope
main.cpp: In function 'int main()':
main.cpp:386:35: error: no matching function for call to 
'TVector<int>::iterator::iterator(TVector<int>::iterator)'
main.cpp:386:35: note: candidates are:
main.cpp:14:3: note: TVector<T>::iterator::iterator(TVector<T>::iterator&) 
[with T = int; TVector<T>::iterator = TVector<int>::iterator]
main.cpp:14:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'TVector<int>::iterator&'
main.cpp:12:3: note: TVector<T>::iterator::iterator() [with T = int]
main.cpp:12:3: note:   candidate expects 0 arguments, 1 provided
main.cpp:11:3: note: TVector<T>::iterator::iterator(T*) [with T = int]
main.cpp:11:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'int*'
main.cpp:387:19: error: no match for 'operator=' in 'pos = TVector<T>::begin() 
[with T = int]()'
main.cpp:387:19: note: candidate is:
main.cpp:17:13: note: TVector<T>::iterator& 
TVector<T>::iterator::operator=(TVector<T>::iterator&) [with T = int; 
TVector<T>::iterator = TVector<int>::iterator]
main.cpp:17:13: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'TVector<int>::iterator&'
main.cpp:391:30: error: no matching function for call to 
'TVector<int>::iterator::iterator(TVector<int>::iterator)'
main.cpp:391:30: note: candidates are:
main.cpp:14:3: note: TVector<T>::iterator::iterator(TVector<T>::iterator&) 
[with T = int; TVector<T>::iterator = TVector<int>::iterator]
main.cpp:14:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'TVector<int>::iterator&'
main.cpp:12:3: note: TVector<T>::iterator::iterator() [with T = int]
main.cpp:12:3: note:   candidate expects 0 arguments, 1 provided
main.cpp:11:3: note: TVector<T>::iterator::iterator(T*) [with T = int]
main.cpp:11:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'int*'
main.cpp:310:11: error:   initializing argument 1 of 'TVector<T>::iterator 
TVector<T>::insert(TVector<T>::iterator, int, T) [with T = int]'
main.cpp:393:32: error: no matching function for call to 
'TVector<int>::iterator::iterator(TVector<int>::iterator)'
main.cpp:393:32: note: candidates are:
main.cpp:14:3: note: TVector<T>::iterator::iterator(TVector<T>::iterator&) 
[with T = int; TVector<T>::iterator = TVector<int>::iterator]
main.cpp:14:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'TVector<int>::iterator&'
main.cpp:12:3: note: TVector<T>::iterator::iterator() [with T = int]
main.cpp:12:3: note:   candidate expects 0 arguments, 1 provided
main.cpp:11:3: note: TVector<T>::iterator::iterator(T*) [with T = int]
main.cpp:11:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'int*'
main.cpp:294:11: error:   initializing argument 1 of 'TVector<T>::iterator 
TVector<T>::erase(TVector<T>::iterator, TVector<T>::iterator) [with T = int]'
main.cpp: In instantiation of 'void show(TVector<T>&) [with T = int]':
main.cpp:376:8:   required from here
main.cpp:356:3: error: dependent-name 'TVector<T>::const_iterator' is parsed as 
a non-type, but instantiation yields a type
main.cpp:356:3: note: say 'typename TVector<T>::const_iterator' if a type is 
meant
main.cpp: In instantiation of 'TVector<T>::iterator TVector<T>::end() [with T = 
int]':
main.cpp:386:35:   required from here
main.cpp:175:31: error: no matching function for call to 
'TVector<int>::iterator::iterator(TVector<int>::iterator)'
main.cpp:175:31: note: candidates are:
main.cpp:14:3: note: TVector<T>::iterator::iterator(TVector<T>::iterator&) 
[with T = int; TVector<T>::iterator = TVector<int>::iterator]
main.cpp:14:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'TVector<int>::iterator&'
main.cpp:12:3: note: TVector<T>::iterator::iterator() [with T = int]
main.cpp:12:3: note:   candidate expects 0 arguments, 1 provided
main.cpp:11:3: note: TVector<T>::iterator::iterator(T*) [with T = int]
main.cpp:11:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'int*'
main.cpp: In instantiation of 'TVector<T>::iterator TVector<T>::begin() [with T 
= int]':
main.cpp:387:19:   required from here
main.cpp:171:22: error: no matching function for call to 
'TVector<int>::iterator::iterator(TVector<int>::iterator)'
main.cpp:171:22: note: candidates are:
main.cpp:14:3: note: TVector<T>::iterator::iterator(TVector<T>::iterator&) 
[with T = int; TVector<T>::iterator = TVector<int>::iterator]
main.cpp:14:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'TVector<int>::iterator&'
main.cpp:12:3: note: TVector<T>::iterator::iterator() [with T = int]
main.cpp:12:3: note:   candidate expects 0 arguments, 1 provided
main.cpp:11:3: note: TVector<T>::iterator::iterator(T*) [with T = int]
main.cpp:11:3: note:   no known conversion for argument 1 from 
'TVector<int>::iterator' to 'int*'

Пробую без поддержки С++11 (g++ v4.2):
main.cpp: In function ‘void show(TVector<T>&)’:
main.cpp:356: error: expected `;' before ‘pos’
main.cpp:357: error: ‘pos’ was not declared in this scope
main.cpp: In function ‘int main()’:
main.cpp:386: error: no matching function for call to 
‘TVector<int>::iterator::iterator(TVector<int>::iterator)’
main.cpp:14: note: candidates are: 
TVector<T>::iterator::iterator(TVector<T>::iterator&) [with T = int]
main.cpp:11: note:                 TVector<T>::iterator::iterator(T*) [with T = 
int]
main.cpp:387: error: no match for ‘operator=’ in ‘pos = 
TVector<T>::begin() [with T = int]()’
main.cpp:17: note: candidates are: TVector<T>::iterator& 
TVector<T>::iterator::operator=(TVector<T>::iterator&) [with T = int]
main.cpp:391: error: no matching function for call to 
‘TVector<int>::iterator::iterator(TVector<int>::iterator)’
main.cpp:14: note: candidates are: 
TVector<T>::iterator::iterator(TVector<T>::iterator&) [with T = int]
main.cpp:11: note:                 TVector<T>::iterator::iterator(T*) [with T = 
int]
main.cpp:391: error:   initializing argument 1 of ‘TVector<T>::iterator 
TVector<T>::insert(TVector<T>::iterator, int, T) [with T = int]’
main.cpp:393: error: no matching function for call to 
‘TVector<int>::iterator::iterator(TVector<int>::iterator)’
main.cpp:14: note: candidates are: 
TVector<T>::iterator::iterator(TVector<T>::iterator&) [with T = int]
main.cpp:11: note:                 TVector<T>::iterator::iterator(T*) [with T = 
int]
main.cpp:393: error:   initializing argument 1 of ‘TVector<T>::iterator 
TVector<T>::erase(TVector<T>::iterator, TVector<T>::iterator) [with T = int]’
main.cpp:393: error: no matching function for call to 
‘TVector<int>::iterator::iterator(TVector<int>::iterator)’
main.cpp:14: note: candidates are: 
TVector<T>::iterator::iterator(TVector<T>::iterator&) [with T = int]
main.cpp:11: note:                 TVector<T>::iterator::iterator(T*) [with T = 
int]
main.cpp:393: error:   initializing argument 2 of ‘TVector<T>::iterator 
TVector<T>::erase(TVector<T>::iterator, TVector<T>::iterator) [with T = int]’
main.cpp: In function ‘void show(TVector<T>&) [with T = int]’:
main.cpp:376:   instantiated from here
main.cpp:356: error: dependent-name ‘TVector<T>::const_iterator’ is parsed 
as a non-type, but instantiation yields a type
main.cpp:356: note: say ‘typename TVector<T>::const_iterator’ if a type is 
meant
main.cpp: In member function ‘TVector<T>::iterator TVector<T>::end() [with T 
= int]’:
main.cpp:386:   instantiated from here
main.cpp:175: error: no matching function for call to 
‘TVector<int>::iterator::iterator(TVector<int>::iterator)’
main.cpp:14: note: candidates are: 
TVector<T>::iterator::iterator(TVector<T>::iterator&) [with T = int]
main.cpp:11: note:                 TVector<T>::iterator::iterator(T*) [with T = 
int]
main.cpp: In member function ‘TVector<T>::iterator TVector<T>::begin() [with 
T = int]’:
main.cpp:387:   instantiated from here
main.cpp:171: error: no matching function for call to 
‘TVector<int>::iterator::iterator(TVector<int>::iterator)’
main.cpp:14: note: candidates are: 
TVector<T>::iterator::iterator(TVector<T>::iterator&) [with T = int]
main.cpp:11: note:                 TVector<T>::iterator::iterator(T*) [with T = 
int]
main.cpp: In member function ‘TVector<T>::const_iterator TVector<T>::cend() 
[with T = int]’:
main.cpp:357:   instantiated from ‘void show(TVector<T>&) [with T = int]’
main.cpp:376:   instantiated from here
main.cpp:183: error: no matching function for call to 
‘TVector<int>::const_iterator::const_iterator(TVector<int>::const_iterator)’
main.cpp:79: note: candidates are: 
TVector<T>::const_iterator::const_iterator(TVector<T>::const_iterator&) [with T 
= int]
main.cpp:64: note:                 
TVector<T>::const_iterator::const_iterator(T*) [with T = int]

1. Конструктор TVector(unsigned int f_cap) лучше 
объявить explicit, чтобы не было возможности 
случайно создать вектор из числа.

2. Зачем делать show другом класса. Вроде бы 
эта функция не использует никакие 
внутренности класса-вектора. Или я 
ошибаюсь?..

3. Не вижу проверки на утечки памяти.

Original comment by aivyu...@gmail.com on 19 May 2013 at 10:22

GoogleCodeExporter commented 9 years ago

Original comment by iakovenk...@gmail.com on 19 May 2013 at 1:22

GoogleCodeExporter commented 9 years ago
1. operator=,operator++,operator-- могут, конечно, 
возвращать что угодно. Но логичнее, если 
они возвращают что-то осмысленное (с целью 
использовать результат применения 
оператора в выражении).

2. Не реализован operator->

3. То же замечание про cbegin/cend, что и со 
списком. Такого метода в задании не было. К 
тому же, их нельзя вызвать у константного 
вектора.

4. Если метод/функция не возвращает 
значение, return писать не обязательно. Хотя, 
конечно, это ошибкой не является.

5. Не вижу константной версии operator[]

6. size/capacity/empty/back/front невозможно вызвать у 
константного вектора

Решение не принято.

Original comment by aivyu...@gmail.com on 19 May 2013 at 2:42

GoogleCodeExporter commented 9 years ago

Original comment by iakovenk...@gmail.com on 20 May 2013 at 5:07

GoogleCodeExporter commented 9 years ago
Нет смысла делать неконст версии методов 
size/capacity/empty.

Вот, например, back имеет смысл делать 2 
версии, т.к. в зависимости от константности 
разная логика (разное возвращаемое 
значение).

Решение принято.

Original comment by aivyu...@gmail.com on 26 May 2013 at 10:59