gpt4 book ai didi

C++ 不匹配运算符 <<

转载 作者:太空狗 更新时间:2023-10-29 23:48:47 26 4
gpt4 key购买 nike

这是我的代码,我不确定为什么会抛出错误 - 该方法应该对指针对象进行操作并打印出它的值。

主要内容:

cout<<"Deleted item is: "<<displayRecord(tmp)/*tmp->entry*/<<endl;


void displayRecord(PRecord* pr) {
cout<<"Time: "<<pr->time<<"\tEntry data: \""<<pr->entry<<'"'<<endl;
}

标题.h:

#include <iostream>
using namespace std;
struct PRecord {
long time;
string entry;
struct PRecord *link;
};

void displayRecord(PRecord* pr);

我收到此错误:error: no match for 'operator <<

 error: no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(& std::cout)), ((const char*)"Deleted item is: ")) << Priority_Queue::displayRecord(tmp)'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:117: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:127: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux

最佳答案

错误很明显你要用

cout << "Deleted item is: " << Priority_Queue::displayRecord(tmp);

但它无法编译,因为 displayRecord不返回任何值。它返回 void键入不可打印且不能用作 operator<< 的参数的内容.调用

cout << "Deleted item is: ";
Priority_Queue::displayRecord(tmp);

关于C++ 不匹配运算符 <<,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52982622/

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