Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法访问类';标准::基本操作系统<_元素,_Traits>';_C++_Visual Studio 2010_Compiler Errors - Fatal编程技术网

C++ 无法访问类';标准::基本操作系统<_元素,_Traits>';

C++ 无法访问类';标准::基本操作系统<_元素,_Traits>';,c++,visual-studio-2010,compiler-errors,C++,Visual Studio 2010,Compiler Errors,此特定方法有问题,但不确定如何解决!我得到的错误如下: 错误C2248:'std::basic_ios::basic_ios':无法 访问类中声明的私有成员 'std::basic_ios'C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream 604“ 我的方法是: ostream operator<<( ostream & stream, ProcessClass const & rhs )

此特定方法有问题,但不确定如何解决!我得到的错误如下:

错误C2248:'std::basic_ios::basic_ios':无法 访问类中声明的私有成员 'std::basic_ios'C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream 604“

我的方法是:

ostream operator<<( ostream & stream, ProcessClass const & rhs )
{
  stream << rhs.name_;
  return stream;
}

ostream操作符返回类型应为
ostream&
,这是对
ostream
的引用

ostream & operator<<( ostream & stream, ProcessClass const & rhs )
{    //^^^ note this!
  stream << rhs.name_;
  return stream;
}

ostream&operator您不能复制流,而是返回引用,更改为

ostream& operator<<( ostream & stream, ProcessClass const & rhs )

ostream&operator令人困惑的是(我不确定我遗漏了什么),当我将其更改为上面的(我以前尝试过)时,我会得到一个错误<代码>错误C2556:'std::ostream&operator@Fids:您在类中定义了两次。为什么定义了两次?
ostream& operator<<( ostream & stream, ProcessClass const & rhs )