在C ++中无法访问std :: basic_ostream [英] std::basic_ostream is inaccessible in C++
问题描述
我收到以下错误,我不确定是什么问题
I get the following error and I'm not sure what the issue is
1 IntelliSense: std :: basic_ostream&__ Elem ,
_Traits> :: basic_ostream(const std :: basic_ostream< _Elem,_Traits>:__ Myt& _Right)[with _Elem = char,_Traits = std :: char_traits](在行中声明
C:\Program Files(x86)\Microsoft Visual Studio
11.0\VC\include\ostream中的82无法访问
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
Book.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
我什至不知道错误告诉我什么
I don't even understand what the error is telling me
推荐答案
我怀疑您使用的是古老的编译器,该编译器禁止复制 std :: ostream
,不可复制,方法是将其复制构造函数设为私有;因此,令人困惑的无法访问错误。
I suspect that you're using an ancient compiler that implements a prohibition on copying std::ostream
, which is not copyable, by making its copy-constructor private; hence the confusing "inaccessible" error.
std :: ostream
是不可复制的。您必须返回引用:
std::ostream
is not copyable. You must return a reference:
ostream &operator<< (ostream& out, const Book & b){
这篇关于在C ++中无法访问std :: basic_ostream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!