したがって、私のプログラムには、Button、Window、および WindowButton といういくつかのクラスがあります。Button はテキストのみで構成され、Window はボタンと座標 (x,y) で構成され、WindowButton は Window で構成されます。WindowButton では、次のように << 演算子をオーバーロードしました。
ostream& operator<<(ostream& out, WindowButton& ref)
{
ref.print();
return out;
}
印刷機能は次のようになります。
void WindowButton::print()
{
theWindow->print();
}
ウィンドウクラスのウィンドウ印刷機能:
void Window::print()
{
char* buttonText = button->getText();
char* theText = new char[strlen(buttonText)+1];
strcpy(theText, buttonText);
cout << endl << "Window with coordinates (" << this->coord.x << "," << this->coord.y << ") , and button text \"" << theText << "\"" << endl;
}
主に:
WindowButton *test = new WindowButton();
cout << endl << test;
test->print();
最後の行は正しい出力を提供しますが、2 行目はメモリ アドレスのみを提供します。私は何を間違っていますか?test->print(); であるため、すべてが正常に機能するはずです。正常に動作します。