"->"的基本操作数具有非指针类型
base operand of ‘->’ has non-pointer type
我在超载<<
输出操作符时遇到麻烦。错误似乎不是重载本身,而是重载内部的实现,因为同样的错误发生在value()
函数中。
DeckOfCards.cpp: In function
std::ostream& deck::operator<<(std::ostream&, const deck::LinkedList&)
:
DeckOfCards.cpp:81:20:错误:->
的基本操作数是非指针的类型const deck::LinkedList
return os << list->value();
DeckOfCards.cpp: In成员函数
void deck::DeckOfCards::value(deck::LinkedList&)
:
DeckOfCards.cpp:100:15:错误:->
的基本操作数是非指针类型deck::LinkedList
cout << list->getListData();
相关代码如下:
DeckOfCards.cpp
// overloaded cout operator
ostream& operator << (ostream& os, const LinkedList& list) {
return os << list->value();
}
// returns all cards as a string
void DeckOfCards::value(LinkedList& list) {
cout << list->getListData();
}
LinkedList.cpp
Node::value_type LinkedList::getListData() {
for (current = head; current != NULL; current = current->getNext()) {
contents += current->getData() + " ";
}
return contents;
}
为什么我得到这些错误?
如果左操作数既不是指针也不是重载->
操作符的类,则不能使用->
操作符。尝试使用.
操作符,如list.value()
和list.getListData()
。
相关文章:
- 非类型指针和引用模板参数,以及在编译时如何/为什么解析它们.c++
- 如何访问在 c++ 中在类内声明的结构类型指针变量?
- (C )找到基本类型指针的儿童类型
- 表达式必须具有指向对象的指针类型(指针向量)
- 将子项复制构造到父类型指针中
- C 返回类型指针声明
- 调用虚拟函数而不通过类类型指针创建任何对象
- C++ 如何使用类类型指针制作向量
- 为什么基类型指针不能获取派生类对象的地址值?
- 如何在 C++ 中获取映射类型指针,映射
- 如何检查该类型的类型指针是正确对齐的
- 正在转换为短类型指针
- 指向任意类方法的模板非类型指针
- 如何通过强制转换类型指针将字符数组转换为uint16_t
- 指向shared_ptr的不透明类型 C 指针
- C++:从值类型指针强制转换为包含迭代器
- C/C++:访问给定类型指针的位置与访问另一类型指针的相同位置不同
- 比较类型指针
- 数据类型指针使用*(Datatype *)
- 如何打印c++中char类型指针的所有值