提问者:小点点

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
}
};

共1个答案

匿名用户

简单如

std::string* p = this;

由于派生自,因此可以隐式地转换为(当然,基类实际上是可以访问的)。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|指向|类|中|私有|继承|类|对象)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?