Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.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++ 使用共享的ptr从函数返回时类型转换 std::shared_ptr parse_input_fiz(char const*input){ std::共享ptr打印机(FizPrinter); 返回打印机; }_C++_Casting_Shared Ptr - Fatal编程技术网

C++ 使用共享的ptr从函数返回时类型转换 std::shared_ptr parse_input_fiz(char const*input){ std::共享ptr打印机(FizPrinter); 返回打印机; }

C++ 使用共享的ptr从函数返回时类型转换 std::shared_ptr parse_input_fiz(char const*input){ std::共享ptr打印机(FizPrinter); 返回打印机; },c++,casting,shared-ptr,C++,Casting,Shared Ptr,从AbstractPrinter继承的FizPrinter。我得到了下一个错误: 说明资源路径位置类型无法转换“打印机” 从“std::shared_ptr(*)(FizPrinter)”到 “std::shared_ptr”parser.cc/pdf-i/src第63行C/C++ 问题 此功能是工厂中使用的一种std::shared_ptr打印机(FizPrinter); std::shared_ptr<AbstractPrinter> parse_input_fiz(char

从AbstractPrinter继承的FizPrinter。我得到了下一个错误:

说明资源路径位置类型无法转换“打印机” 从“std::shared_ptr(*)(FizPrinter)”到 “std::shared_ptr”parser.cc/pdf-i/src第63行C/C++ 问题


此功能是工厂中使用的一种

std::shared_ptr打印机(FizPrinter);
std::shared_ptr<AbstractPrinter> parse_input_fiz(char const *input) {
    std::shared_ptr<FizPrinter> printer(FizPrinter);

    return printer;
}
表示“打印机是带有参数FizPrinter的函数”

见问题10.21:

std::共享打印机(FizPrinter);
表示“打印机是带有参数FizPrinter的函数”

见问题10.21:

你的意思是什么

std::shared_ptr<FizPrinter> printer(FizPrinter);
std::共享打印机(新的FizPrinter());
您当前的代码声明了一个函数,而
共享\u ptr
的构造函数接受一个指针。

您的意思是

std::shared_ptr<FizPrinter> printer(FizPrinter);
std::共享打印机(新的FizPrinter());

您当前的代码声明了一个函数,而
shared\u ptr
的构造函数接受一个指针。

或者更好的是,
return std::make_shared()或者更好,
返回std::make_shared()