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、 重置()//如上