c++ - C ++如何指向类中的私有继承类对象
问题描述
我正在学习类继承,我想知道如何创建指向另一个类私有继承的类的指针?我在下面包含了一个简单的示例。非常感谢那些帮助回答这个问题的人。
class A: private std::string
{
public:
A(){}
~A(){}
void func1()
{
// I want a pointer that points to the std::string object. Then I will use that pointer in this function
}
};
解决方案
简单到
std::string* p = this;
由于A
派生自std::string
,A*
可以隐式转换为std::string*
(当然,该基类实际上是可访问的)。
推荐阅读
- delphi-7 - 如何在 Delphi 7 中使用 OnGetPassword 发送密码以建立 SSL 连接
- python - Pvlib-Python 日期时间错误“不能转换为日期时间”
- java - 在 Android SDK 29 中管理 WiFi 网络共享
- python - 用于分类的字符串操作
- ios - iPadOS 13.4 Ble 配对弹出窗口在没有读/写受保护特征的情况下触发
- mysql - "LOAD" 在此位置对于服务器版本无效..." // 错误代码:1064。您的 SQL 语法有错误
- dart - Don't explicitly initialize variables to null
- javascript - IPFS 问题:无法使用 ipfs.add(file) 上传文件
- ios - 添加 SearchController 会导致导航栏变黑
- flutter - 使用 google_maps_flutter 检查坐标是否在颤振中的多边形内