Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何强制转换std::make_唯一,以便使用类中声明的函数?_C++_Class_Oop_C++11 - Fatal编程技术网

C++ 如何强制转换std::make_唯一,以便使用类中声明的函数?

C++ 如何强制转换std::make_唯一,以便使用类中声明的函数?,c++,class,oop,c++11,C++,Class,Oop,C++11,或者我需要将std::make_unique转换成任何形式吗 我有一个FOO类,其中包含一些可以使用的函数: FOO::FOO(const yoo &yoo, float numbers) : num_to_execute(numbers) { ... ... } void FOO::execute() { execute(num_to_execute); } 在另一个.cpp中,我的给定代码使用以下方法初始化foo: new_foo = std:

或者我需要将
std::make_unique
转换成任何形式吗

我有一个FOO类,其中包含一些可以使用的函数:

 FOO::FOO(const yoo &yoo, float numbers) :
     num_to_execute(numbers)
 {
 ...
 ...
 }

 void FOO::execute()
 {
    execute(num_to_execute);
 }
在另一个.cpp中,我的给定代码使用以下方法初始化foo:

 new_foo = std::make_unique<FOO>(yoo, number);
但它说:

  error: 'class std::unique_ptr<WORK::TOBEDONE::FOO>' has no member named 'EXECUTE'
错误:“class std::unique\u ptr”没有名为“EXECUTE”的成员
execute
应该能够调用成员
,但是std::unique\u ptr让我很难理解我应该做什么。

new\u foo->execute()

unique\u ptr
在这个意义上的行为类似于常规指针,并且有一个
操作符->
操作符*
重载

当使用
->
*
访问指针对象时,可以使用常规点(
)访问
唯一的ptr
函数(如
std::unique\u ptr::get

auto str = std::make_unique<std::string>("hello world");
auto i = std::make_unique<int>(5);

str->size();
*i = 4;
str.reset(); //deletes the pointee and make str point to null
i.reset(); //as above
auto str=std::使_独一无二(“你好世界”);
自动i=标准::使_唯一(5);
str->size();
*i=4;
str.reset()//删除指针对象并使str指向null
i、 重置()//如上
new_foo->execute()

unique\u ptr
在这个意义上的行为类似于常规指针,并且有一个
操作符->
操作符*
重载

当使用
->
*
访问指针对象时,可以使用常规点(
)访问
唯一的ptr
函数(如
std::unique\u ptr::get

auto str = std::make_unique<std::string>("hello world");
auto i = std::make_unique<int>(5);

str->size();
*i = 4;
str.reset(); //deletes the pointee and make str point to null
i.reset(); //as above
auto str=std::使_独一无二(“你好世界”);
自动i=标准::使_唯一(5);
str->size();
*i=4;
str.reset()//删除指针对象并使str指向null
i、 重置()//如上