C++ 编译器返回";合成方法&x2018;运算符=’;“此处第一个要求”;
我知道这可能是一个简单的问题,但我已经研究了一个半小时,我真的迷路了 以下是编译器错误:C++ 编译器返回";合成方法&x2018;运算符=’;“此处第一个要求”;,c++,gcc,C++,Gcc,我知道这可能是一个简单的问题,但我已经研究了一个半小时,我真的迷路了 以下是编译器错误: synthesized method ‘File& File::operator=(const File&)’ first required here 我有一段代码: void FileManager::InitManager() { int numberOfFile = Settings::GetSettings()->NumberOfFile() + 1; f
synthesized method ‘File& File::operator=(const File&)’ first required here
我有一段代码:
void FileManager::InitManager()
{
int numberOfFile = Settings::GetSettings()->NumberOfFile() + 1;
for( unsigned int i = 1; i < numberOfFile; i++ )
{
std::string path = "data/data" ;
path += i;
path += ".ndb";
File tempFile( path );
_files.push_back( tempFile ); // line that cause the error
/*if( PRINT_LOAD )
{
std::cout << "Adding file " << path << std::endl;
}*/
}
}
void文件管理器::InitManager()
{
int numberOfFile=Settings::GetSettings()->numberOfFile()+1;
for(无符号整数i=1;i std::cout我不确定错误消息,但这行:
_files.push_back( tempFile );
要求文件
有一个公共副本构造函数。既然你提供了其他构造函数,你也必须提供这个构造函数。编译器不合成它。在C++03中,std::vector
要求t
是可复制构造和可复制分配的。文件
包含标准流数据成员s、 标准流是不可复制的,因此文件也不可复制
您的代码在C++11(使用移动构造/移动分配)中可以正常工作,但您需要避免在C++03中按值保存标准流对象作为数据成员。我建议将编译器升级到支持C++11移动语义的编译器,或使用其中一种
#pragma once
//C++ Header
#include <fstream>
#include <vector>
#include <string>
//C Header
//local header
class File
{
public:
File();
File( std::string path );
~File();
std::string ReadTitle();
void ReadContent();
std::vector<std::string> GetContent();
private:
std::ifstream _input;
std::ofstream _output;
char _IO;
std::string _path;
std::vector<std::string> _content;
};
#include "file.h"
File::File()
: _path( "data/default.ndb" )
{
}
File::File( std::string path )
: _path( path )
{
}
File::~File()
{
}
void File::ReadContent()
{
}
std::string File::ReadTitle()
{
_input.open( _path.c_str() );
std::string title = "";
while( !_input.eof() )
{
std::string buffer;
getline( _input, buffer );
if( buffer.substr( 0, 5 ) == "title" )
{
title = buffer.substr( 6 ); // 5 + 1 = 6... since we want to skip the '=' in the ndb
}
}
_input.close();
return( title );
}
std::vector<std::string> File::GetContent()
{
return( _content );
}
_files.push_back( tempFile );