我似乎在尝试创建指向“this”的指针的项目中遇到问题,其中“this”是 C++ 列表中的第一个 LinkedList。第一个对象中包含数据,第二个对象中有数据……等等,this->m_next
直到NULL
编译器向我吐出这个:
linkedlist.hpp:55:22: error: invalid conversion from âconst LinkedList<int>* constâ to âLinkedList<int>*â [-fpermissive]
我究竟做错了什么?
template <typename T>
int LinkedList<T>::size() const
{
int count = 0;
LinkedList* list = this; // this line is what the compiler is complaining about
//adds to the counter if there is another object in list
while(list->m_next != NULL)
{
count++;
list = list->m_next;
}
return count;
}