Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误:‘;班级名单<;RGBApixel>’;没有名为‘的成员;货币’;链表_C++_Linked List - Fatal编程技术网

C++ 错误:‘;班级名单<;RGBApixel>’;没有名为‘的成员;货币’;链表

C++ 错误:‘;班级名单<;RGBApixel>’;没有名为‘的成员;货币’;链表,c++,linked-list,C++,Linked List,我不知道为什么会出现这样的错误:list.cpp:127:error:“class list”没有名为“curr”的成员 template <class T> List<T> List<T>::mixSplit() { List<T> * newList; class List<T>::ListNode * curr = head; newList->length=0; newList->l

我不知道为什么会出现这样的错误:list.cpp:127:error:“class list”没有名为“curr”的成员

template <class T>
List<T> List<T>::mixSplit()
{
    List<T> * newList;
    class List<T>::ListNode * curr = head;

    newList->length=0;
    newList->length-3;
    newList->head = NULL;
    newList->tail=NULL;

    for (int count=0;count<1;count++)
        newList->curr=newList->curr->next;

    newList->head=newList->curr;
    newList->tail=tail;

    tail=newList->curr->prev;
    tail->next=NULL;

    newList->head->prev=NULL;
    newList->tail->next=NULL;

    return newList;
}
当我这样做时:

    class List<T>::ListNode * curr = head;

使用
typename
代替
class

typename List<T>::ListNode * curr = head; //correct
//class List<T>::ListNode * curr = head; //incorrect
typename List::ListNode*curr=head//对的
//类列表::ListNode*curr=head//不正确的
这是一个无法使用
class
代替
typename
的示例

错误:list.cpp:127:错误:“类列表”没有名为“curr”的成员

template <class T>
List<T> List<T>::mixSplit()
{
    List<T> * newList;
    class List<T>::ListNode * curr = head;

    newList->length=0;
    newList->length-3;
    newList->head = NULL;
    newList->tail=NULL;

    for (int count=0;count<1;count++)
        newList->curr=newList->curr->next;

    newList->head=newList->curr;
    newList->tail=tail;

    tail=newList->curr->prev;
    tail->next=NULL;

    newList->head->prev=NULL;
    newList->tail->next=NULL;

    return newList;
}

从错误中可以清楚地看出,模板的定义位于
.cpp
文件中。这是问题的另一个原因。不能在其他文件中提供模板的定义。声明和定义应该在同一个文件中。因此,将所有定义移动到头文件。

列表
没有成员
curr
,这就是错误说明的内容。我很确定这个班确实没有这个成员


在不同的作用域中有另一个变量具有相同的名称这一事实是不相关的。

问题是在
列表中没有像,
curr
这样的成员!您误解了,
curr
List::ListNode
的成员

仅仅在
内部声明
并不意味着所有的内部类成员也委托给外部类,反之亦然。您需要有
ListNode*curr内部
列表
来完成此操作

在解决编译器错误后,您将最终解决运行时错误,因为您的类还有其他几个问题。比如说,

List<T> * newList;  // dangling/uninitialized pointer
class List<T>::ListNode * curr = head;  // curr is unused and pointing to something unknown
List*newList;//悬空/未初始化指针
类列表::ListNode*curr=head;//curr未使用并且指向未知的内容

您必须初始化
newList=newList
以使用指针。或者您可以将自动对象声明为
List newList

发布类列表的定义如何?您需要发布错误。从给定的代码来看,它看起来不错。我不确定这是否是代码前面的问题,我可以使用指针curr,但由于某种原因,当我尝试使用newList时,没有获得成员curr。我只想分配一个指向新列表头的指针。您是对的,这是一个
class
无法替换
typename
的示例。但是,对于用户定义的类。另外,如果
typename
是一个问题,那么错误行将不同。@user949358:为什么不发布
列表的代码?还要让我们知道标题和源文件。@Nawaz添加了类定义,我只是不知道如何将指针分配给newList@user949358:我在定义中没有看到任何成员
curr
。为什么你看不到你发布的内容,以及你试图访问的成员?
List<T> * newList;  // dangling/uninitialized pointer
class List<T>::ListNode * curr = head;  // curr is unused and pointing to something unknown