0

クラスの継承について学習していますが、別のクラスによってプライベートに継承されたクラスへのポインターを作成する方法を知りたいですか? 以下に簡単な例を含めました。この質問への回答を手伝ってくれた人々に感謝します。

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

1 に答える 1

2

単純な

std::string* p = this;

からA派生しているためstd::stringA*暗黙的に変換std::string*可能です (もちろん、その基本クラスは実際にアクセス可能です)。

于 2020-12-19T14:04:23.713 に答える