gpt4 book ai didi

c++ - 我想使用非静态对象变量作为默认方法参数

转载 作者:行者123 更新时间:2023-11-30 01:26:43 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
c++ publicly inherited class member cannot be used as default argument
Nonstatic member as a default argument of a nonstatic member function

LinkedInteger accessElement(int index, LinkedInteger *startElement=&DataArray[0]){ // Starting at *startElement*, returns the element which is at the index of *startElement+index

LinkedInteger NullElement;
if (index<0){
cout << "Index degeri sifirdan buyuk olmalidir" << endl;
NullElement.value=0;
NullElement.nextPtr=0;
return NullElement;
}
for (int i=0; i<index; i++){
if (startElement->nextPtr == NULL){ // Last elements index is null.
cout << " Erismeye calistiginiz eleman dizi sinirlarinin disindadir " << endl;
NullElement.value=0;
NullElement.nextPtr=0;
return NullElement;}
else {
startElement=startElement->nextPtr;
}
}
return *startElement;
}

这是在 C++ 中实现链表的一种方法,它只允许访问列表元素我想将 header 作为默认参数(实际上是 DataArray[0])。由于错误“无效使用非静态数据成员”而失败。

this->&DataArray[0]

也因为“this may not be used in this context”而失败我该怎么办?

代码的上下文也存在一些问题。请忽略它们。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com