c++ - 使用现有的类成员指针从类外部调用函数
问题描述
我遇到了一个与智能指针相关的问题。我有一个继承自类Cell的类Property ,我想将当前类成员指针传递给Player类成员函数。
class Player {
private:
std::vector<std::shared_ptr<Cell>> cells;
int money;
public:
bool buysProperty(std::shared_ptr<Cell> property)
{
//some code in which i would like to call both Cell and Property functions
}
};
这就是我从 Property 类内部调用此函数的方式:
class Property : public Cell {
private:
public:
void action(Player* currentPlayer) {
currentPlayer->buysProperty(std::make_shared<Property>(this)) {
}
}
};
编译后我得到这个错误: 'Property::Property(const Property &)': cannot convert argument 1 from '_Ty' to 'const Property &'
我不知道出了什么问题,是我调用函数错误,还是函数体有问题?也许是“this”关键字问题?谢谢你所有的时间和答案:)
解决方案
推荐阅读
- python - Python中的外观模式
- php - 使用 FireFox 时,WordPress php 代码未在页面上呈现
- python - 如何在熊猫数据框中找到最后一个事件的日期
- java - 带有 ServiceAccount 错误 401 的 Gmail Java API
- system-verilog - v2k 库的 SV lrm 解释
- xamarin.forms - Xamarin Forms In App Billing 插件不起作用
- ocaml - OCaml:列表@ [x] vs x ::列表
- php - 如何防止mysql中没有主键的重复
- open-liberty - OpenLiberty 抛出 javax.net.ssl.SSLHandshakeException
- javascript - 收到错误:无法获取 / 尽管链接了 HTML 文件