所以我在下面的文件,其內容如下: 啊: #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: