所以我在下面的文件,其内容如下: 啊: #ifndef A_H
#define A_H
class A {
};
#endif
BH: #ifndef B_H
#define B_H
#include <memory>
class A;
class B {
public:
B(std::unique_ptr<A> a);
private:
st
这是我的理解,当一个基本的数据类型被移出时,它将始终执行一个副本。 例如,你永远无法从int移动,并有原始int没有指定值: #include <iostream>
int main() {
int x = 100;
int y{std::move(x)};
std::cout << x << " " << y; //always prints "100 100
假设验证码: class Parent {}
class Child : public Parent {}
static std::vector<std::unique_ptr<Child>> Foo();
有没有写这个功能的一个简单的方法: std::vector<std::unique_ptr<Parent>> Bar() {
auto children = Foo();
假设有这样的功能,移动: int * func()
{
std::unique_ptr<int> ptr(new int(3));
//Few more lines of code
//then one function added where programmer writes like some thing
SOME_OTHER_FUNC(std: