gpt4 book ai didi

c++ - std::basic_ostream 在 C++ 中不可访问

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

我收到以下错误,我不确定是什么问题

1 IntelliSense: "std::basic_ostream<_Elem, _Traits>::basic_ostream(const std::basic_ostream<_Elem, _Traits>::_Myt &_Right) [with _Elem=char, _Traits=std::char_traits]" (declared at line 82 of "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\ostream") is inaccessible

图书.cpp

ostream operator<< (ostream& out, const Book & b){
out << "Title: " << b.my_Title << endl;
out << "Author: " << b.my_Author << endl;
out << "Number of time checkout out: " << b.my_NumberOfTimesCheckedOut;
return(out);
}

我遇到了 return(out);

的问题

Book.h

#ifndef BOOK_H
#define BOOK_H
#include <string>
using namespace std;
namespace CS20A
{
class Book {
public:
Book();
Book( string author, string title );
string getTitle() const;
string getAuthor() const;
int getNumberOfTimesCheckedOut() const;
void increaseNumberOfTimesCheckedOut( int amount=1 );
friend ostream operator<< ( ostream& out, const Book & b );
private:
string my_Author;
string my_Title;
int my_NumberOfTimesCheckedOut;
};
};
#endif

我什至不明白错误在告诉我什么

最佳答案

我怀疑您正在使用一个古老的编译器,该编译器通过将其复制构造函数设为私有(private)来禁止复制不可复制的 std::ostream;因此会出现令人困惑的“无法访问”错误。

std::ostream 不可复制。您必须返回引用:

ostream &operator<< (ostream& out, const Book & b){

关于c++ - std::basic_ostream 在 C++ 中不可访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38089332/

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