草庐IT

Make_shared

全部标签

c++ - 标准 <memory> 文件中 boost::shared_ptr 和 std::shared_ptr 之间的区别

我想知道boost::shared_ptr之间是否有任何区别和std::shared_ptr在标准中找到文件。 最佳答案 std::shared_ptr是tr1::shared_ptr的C++0x形式,boost的boost::shared_ptr应该表现一样。然而,std::shared_ptr,在符合C++0x标准的实现中,应该/可能对shared_ptr类有更方便的行为,如所述在以下链接中:Differencesbetweendifferentflavoursofshared_ptrhttp://en.wikipedia.or

c++ - 标准 <memory> 文件中 boost::shared_ptr 和 std::shared_ptr 之间的区别

我想知道boost::shared_ptr之间是否有任何区别和std::shared_ptr在标准中找到文件。 最佳答案 std::shared_ptr是tr1::shared_ptr的C++0x形式,boost的boost::shared_ptr应该表现一样。然而,std::shared_ptr,在符合C++0x标准的实现中,应该/可能对shared_ptr类有更方便的行为,如所述在以下链接中:Differencesbetweendifferentflavoursofshared_ptrhttp://en.wikipedia.or

c++ - 如何让 std::make_unique 成为我类的 friend

我想将std::make_unique函数声明为我类(class)的friend。原因是我想声明我的构造函数protected并提供另一种使用unique_ptr创建对象的方法。这是一个示例代码:#includetemplateclassA{public://SomehowIwanttodeclaremake_uniqueasafriendfriendstd::unique_ptr>std::make_unique>();staticstd::unique_ptrCreateA(Tx){//returnstd::unique_ptr(newA(x));//worksreturnstd:

c++ - 如何让 std::make_unique 成为我类的 friend

我想将std::make_unique函数声明为我类(class)的friend。原因是我想声明我的构造函数protected并提供另一种使用unique_ptr创建对象的方法。这是一个示例代码:#includetemplateclassA{public://SomehowIwanttodeclaremake_uniqueasafriendfriendstd::unique_ptr>std::make_unique>();staticstd::unique_ptrCreateA(Tx){//returnstd::unique_ptr(newA(x));//worksreturnstd:

ruby-on-rails - rails : Is there a way to make nested resources work automatically with `link_to` ?

我有一个带有嵌套资源的Rails应用程序,例如:resources:productdoresources:salesendSalebelongs_toProduct,Sale实例不能没有产品。我可以使用link_to+@product直接链接到产品:产生StrawberryJam但是,如果我想做类似的销售,我不能单独使用@sale。我必须涉及产品。这行不通:我必须使用这样的东西:第一种情况不会起作用,因为sale_path未定义(只有product_sale_path是)。我的问题是:我能否向Sale模型中添加一些内容,以便link_to(或url_for)自动添加“parent”(在

c++ - 通过 make_unique/make_shared 调用 initializer_list 构造函数

我正在尝试使用std::make_unique来实例化一个类,其构造函数将接收std::initializer_list。这是一个最小的案例:#include#include#include#includestructFoo{Foo(std::initializer_liststrings):strings(strings){}std::vectorstrings;};intmain(int,char**){autoptr=std::make_unique({"Hello","World"});return0;}您可以在Coliru上查看它没有建立:main.cpp:14:56:err

c++ - 通过 make_unique/make_shared 调用 initializer_list 构造函数

我正在尝试使用std::make_unique来实例化一个类,其构造函数将接收std::initializer_list。这是一个最小的案例:#include#include#include#includestructFoo{Foo(std::initializer_liststrings):strings(strings){}std::vectorstrings;};intmain(int,char**){autoptr=std::make_unique({"Hello","World"});return0;}您可以在Coliru上查看它没有建立:main.cpp:14:56:err

c++ - 使用 make_shared 时会发生什么

我很感兴趣这两行代码是否相同:shared_ptrsp(newint(1));//doubleallocation?shared_ptrsp(make_shared(1));//justoneallocation?如果这是真的,有人能解释一下为什么第二行只有一个分配吗? 最佳答案 第一种情况不执行双重分配,它执行两次分配,一个用于托管对象,一个用于shared_ptr控制block/。对于第二种情况,cppreference有一个很好的解释为什么std::make_shared通常只执行它所说的一次内存分配(强调我的future):

c++ - 使用 make_shared 时会发生什么

我很感兴趣这两行代码是否相同:shared_ptrsp(newint(1));//doubleallocation?shared_ptrsp(make_shared(1));//justoneallocation?如果这是真的,有人能解释一下为什么第二行只有一个分配吗? 最佳答案 第一种情况不执行双重分配,它执行两次分配,一个用于托管对象,一个用于shared_ptr控制block/。对于第二种情况,cppreference有一个很好的解释为什么std::make_shared通常只执行它所说的一次内存分配(强调我的future):

ruby - Ruby 编译时 "--enable-shared"是什么意思?

RVM将此标志用于./configure。它的意思是“为Ruby构建一个共享库”,但是我在哪里可以获得有关使用此编译标志时实际发生的更多信息? 最佳答案 它将创建libruby.so以便其他程序可以使用它,例如支持Ruby的Vim。 关于ruby-Ruby编译时"--enable-shared"是什么意思?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/18246610/