C++ 通过函数传递 std::shared_ptr<RECT>
C++ passing std::shared_ptr<RECT> through function
void PlayerHealthBar::SetSourceRect(std::shared_ptr<RECT> sourceRect)
{
this->sourceRect = sourceRect;
}
.CPP 文件我正在尝试从中设置源矩形
playerHealthBar->SetSourceRect(std::shared_ptr<RECT>(0.0, 0.0, 0.0, 0.0));
错误出在shared_ptr<RECT>
上的.cpp文件上,上面写着:
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
我不确定这意味着什么。谢谢。
你应该提供一个动态分配的指针,指向std::shared_ptr
的构造函数。或者,您也可以(我推荐它)使用"工厂功能"std::make_shared
,如下所示:
playerHealthBar->SetSourceRect(std::make_shared<RECT>(0.0, 0.0, 0.0, 0.0));
// ^^^^^^^^^^^
当然,假设RECT
在其构造函数之一中接受 4 个双文本可转换类型。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 如何显式调用运算符<<
- OpenCV Rect x 和 y 表示 (column,row) 或 (row,column)
- 模板操作员&lt;未打电话
- C / CUDA中的模板方法是3个角括号(&lt;&lt;&lt;)
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 错误:调用"std::vector<:vector<int>>::p ush_back(std::vector<std::__cxx11::basic_string<
- C 建造者Clang STD :: Sill,找不到超载的操作员&lt;
- 为什么STD :: MAP需要操作员&lt;以及我如何写一个
- 为什么“操作员”需要const但不是为“运营商&lt;”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- OpenCV断言对RECT ROI失败了
- 使 ShowHint 使用多个不同的 Rect 处理自定义控件,每个 Rect 都有自己的 Hint
- Qt QGraphicsScene::setSceneRect() 实际上并没有设置场景 rect
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla