我知道這可能是一個簡單的問題,但我一直在努力在過去的一個半小時,我真的失去了。編譯器返回「合成方法‘運算符=’在這裏首先需要」
在這裏,編譯器錯誤:
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;
}*/
}
}
_files如果在該標頭中定義:
#pragma once
//C++ Header
#include <vector>
//C Header
//local header
#include "file.h"
class FileManager
{
public:
static FileManager* GetManager();
~FileManager();
void LoadAllTitle();
private:
FileManager();
static FileManager* _fileManager;
std::vector<File> _files;
};
文件是一個對象我創建,它只不過是一個處理文件IO的簡單界面。過去我已經完成了用戶定義對象的向量,但這是我第一次發現這個錯誤。
下面是File對象的代碼: File.h
#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;
};
File.cpp
#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);
}
我在linux下工作與海灣合作委員會。
任何提示或提示,以什麼解決方案,可以理解。
很抱歉的長期職位。
感謝