最近我在看一个开源的腾讯的 json parser ,在同类 parser 里面据说速度第一( rapidjson ),它那个里面有个类叫 Document ,我在封装的时候写了这么一个函数
rapidjson::Document JsonParser::getJsonDocument(std::string filename)
{
// open the JSON file
std::ifstream jFile(filename);
if(!jFile.is_open())
throw JsonParserException("Unable to open file " + filename + ".");
// read the file contents
std::stringstream contents;
contents << jFile.rdbuf();
rapidjson::Document doc;
doc.Parse(contents.str().c_str());
return doc;
}
他在最后 return doc 那里给我报错(只能传引用或者指针)。我去头文件一看,Document 这个类的拷贝构造函数是私有的。上面还有一行注释写着 prohibit copying 。
我就想咨询一下各位大佬(我实在是刚工作的萌新),在什么情况下你们会把拷贝构造函数放在私有里面?这样做是为了实现什么目的呢?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://study.congcong.us/t/885397
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.