Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.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++ C++;通过标准::共享\u ptr<;RECT>;通过功能 void PlayerHealthBar::SetSourceRect(std::shared_ptr sourceRect) { 此->sourceRect=sourceRect; }_C++_Rect - Fatal编程技术网

C++ C++;通过标准::共享\u ptr<;RECT>;通过功能 void PlayerHealthBar::SetSourceRect(std::shared_ptr sourceRect) { 此->sourceRect=sourceRect; }

C++ C++;通过标准::共享\u ptr<;RECT>;通过功能 void PlayerHealthBar::SetSourceRect(std::shared_ptr sourceRect) { 此->sourceRect=sourceRect; },c++,rect,C++,Rect,.CPP文件我正在尝试从中设置源rect void PlayerHealthBar::SetSourceRect(std::shared_ptr<RECT> sourceRect) { this->sourceRect = sourceRect; } playerHealthBar->SetSourceRect(std::shared_ptr(0.0,0.0,0.0,0.0)); shared\ptr上的.cpp文件中出现错误,说明: playerHealthBar

.CPP文件我正在尝试从中设置源rect

void PlayerHealthBar::SetSourceRect(std::shared_ptr<RECT> sourceRect)
{
    this->sourceRect = sourceRect;
}
playerHealthBar->SetSourceRect(std::shared_ptr(0.0,0.0,0.0,0.0));
shared\ptr
上的.cpp文件中出现错误,说明:

playerHealthBar->SetSourceRect(std::shared_ptr<RECT>(0.0, 0.0, 0.0, 0.0));
8 IntelliSense:构造函数“std::shared_ptr::shared_ptr[with _Ty=RECT]”的实例与参数列表不匹配
参数类型为:(双精度,双精度,双精度).\Ship.cpp 84

我不知道这意味着什么。谢谢。

您应该为的构造函数提供一个动态分配的指针。或者,我建议您也可以使用“工厂功能”,如下所示:

8   IntelliSense: no instance of constructor "std::shared_ptr<_Ty>::shared_ptr [with _Ty=RECT]" matches the argument list
            argument types are: (double, double, double, double)    ...\Ship.cpp    84
playerHealthBar->SetSourceRect(标准::使_共享(0.0,0.0,0.0,0.0));
//                                  ^^^^^^^^^^^
当然,假设
RECT
在其一个构造函数中接受4个双文本可转换类型

playerHealthBar->SetSourceRect(std::make_shared<RECT>(0.0, 0.0, 0.0, 0.0));
//                                  ^^^^^^^^^^^