jjzjj

Uncopyable

全部标签

c++继承私有(private)复制构造函数: how doesn't this yield a compile time error?

在C++中,如果我们有这个类classUncopyable{public:Uncopyable(){}~Uncopyable(){}private:Uncopyable(constUncopyable&);Uncopyable&operator=(constUncopyable&);};然后我们有一个派生类classDervied:privateUncopyable{};我的问题是:当编译器在派生类中生成默认的复制构造函数和赋值运算符时,为什么这不会生成编译时错误?生成的代码不会尝试访问基类私有(private)成员吗? 最佳答案

C++11/VS2010 : Returning containers of uncopyable but movable objects

考虑以下代码:#include#includestructA:privateboost::noncopyable{A(intnum,conststd::string&name):num(num),name(name){}A(A&&other):num(other.num),name(std::move(other.name)){}intnum;std::stringname;};std::vectorgetVec(){std::vectorvec;vec.emplace_back(A(3,"foo"));//vec.emplace_back(3,"foo");notavailabley