30.11.2013, 13:48. Просмотров 512. Ответов 3
Ребята, вот есть у меня такой List:
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
| template<class T>
class List
{
public:
typedef T* iterator;
typedef const T* const_iterator;
typedef T value_type;
List();
~List();
void push_front(const T& val);
void push_back(const T& val);
void insertAt(size_t id, const T& val);
bool pop_front();
bool pop_back();
bool isEmpty() const { return first == 0; }
void print() const;
void rprint() const;
size_t size() { return last - first; }
List& operator=(const List& l);
private:
Node<T>* first;
Node<T>* last;
Node<T>* getNewNode(const T& val);
}; |
|
И я хочу вернуть List из функции split:
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
| int main()
{
std::string str = "Hello my name is Slava";
List<std::string> l = split(str);
return 0;
}
List<std::string> split(std::string& s)
{
List<std::string> sl;
std::string::iterator first = s.begin();
while(first != s.end())
{
first = std::find_if(first, s.end(), is_not_space);
std::string::iterator second = std::find_if(first, s.end(), is_space);
if(first != s.end())
sl.push_back(std::string(first, second));
first = second;
}
return sl;
} |
|
В итоге у меня вылазит окошко "прекращение работы программы".
Возможно у меня функция operator= не правильно написана:
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| List<T>& List<T>::operator=(const List<T>& l)
{
if(this != &l)
{
Node<T>* current = l.first;
while(current != 0)
{
this->push_back(current->d);
current = current->next;
}
}
return *this;
} |
|
Буду благодарен за любую подсказку