#include <initializer_list>
#include <iostream>
template <typename T>
class List {
struct Node;
class Iterator;
public:
List() {
std::initializer_list<T> empty;
}
List(std::initializer_list<T> ele) {
this->operator=(ele);
}
std::size_t Size() const {
int count = 0;
Node* current = start;
while (current != NULL) {
count++;
current = current->next;
}
return count;
}
void Insert(T ele) {
Node* node = new Node{ele};
if (this->size == 0) {
this->start = this->end = node;
} else {
this->end->next = node;
node->prev = this->end;
this->end = node;
}
++this->size;
}
void RemoveFront() {
Node* front = this->start;
this->start = front->next;
delete front;
}
T& Front() const {
if (Size() <= 0) {
return Front();
}
Node* Front = start;
return Front->data;
}
List& operator=(std::initializer_list<T> ele) {
this->size = 0;
for (auto&& val : ele) this->Insert(val);
return *this;
}
friend std::ostream& operator<<(std::ostream& out, const List& list) {
for (auto val = list.start; val; val = val->next) {
out << val->data;
if (val->next) out << ",";
}
return out;
}
Iterator begin() {
return Iterator(start);
}
Iterator last() {
return Iterator(end);
}
private:
struct Node {
T data;
Node* next = nullptr;
Node* prev = nullptr;
};
class Iterator {
friendclass List;
typename List<T>::Node* current;
List<T>* theList;
public:
};
Node* start = nullptr;
Node* end = nullptr;
std::size_t size = 0;
};
int main() {
List<char> test = {'H', 'e', 'l', 'l', 'o'};
std::cout << test << std::endl;
test.begin();
std::cout << " = " << test.Front() << std::endl;
}
testings.cpp:68:12: error: no matching conversion for functional-style cast from
'List<char>::Node *' to 'List<char>::Iterator'
return Iterator(start);