Diese erste Frage wurde für das Löschen durch Administrator markiert. Ich habe die Frage aktualisiert, um relevanter zu sein, damit jemand anderes hier von den Antworten profitiert.#include
#include
// some COM #includes might be missing here but hopefully the message is not lost in this example
// various does not know any classes so LPVOID/void* is used
typedef struct various
{
LPVOID drawobj = nullptr;
int a = 0;
int b = 0;
} various;
class dlgcommon
{
public:
virtual void DoThis(MSG dlg_msg) = 0;
virtual void DoThat(MSG dlg_msg) = 0;
dlgcommon() {}
~dlgcommon() {}
};
class imagecallback
{
public:
virtual void Draw_This(ID2D1RenderTarget *arg_tgt) = 0;
virtual void Draw_That(ID2D1RenderTarget *arg_tgt) = 0;
imagecallback() {}
~imagecallback() {}
};
class dlgderived : public dlgcommon, public imagecallback
{
public:
// dlgcommon contract
void DoThis(MSG dlg_msg) override {}
void DoThat(MSG dlg_msg) override {}
// imagecallback contract
void Draw_This(ID2D1RenderTarget *arg_tgt) override {}
void Draw_That(ID2D1RenderTarget *arg_tgt) override {}
dlgderived() {}
~dlgderived() {}
};
// This method works fine
void Test_Via_Base_Ptr(imagecallback *basedraw)
{
// sample code
ID2D1HwndRenderTarget *render_tgt = nullptr;
basedraw->Draw_This(render_tgt);
basedraw->Draw_That(render_tgt);
}
// This method does not work; the app crashes or gets stuck in a loop while in the debugger
void Test_Via_Data(various data)
{
// sample code
ID2D1HwndRenderTarget *render_tgt = nullptr;
auto base_s = static_cast(data.drawobj);
auto base_d = dynamic_cast(data.drawobj);
// this method does not work
base_s->Draw_This(render_tgt);
base_s->Draw_That(render_tgt);
// this method does not work
base_d->Draw_This(render_tgt);
base_d->Draw_That(render_tgt);
}
int main()
{
dlgderived mydlg;
// This method works fine
Test_Via_Base_Ptr(&mydlg);
// This method does not work
various mydata = { (LPVOID)&mydlg, 0, 0 };
Test_Via_Data(mydata);
}
< /code>
Wenn ich Base_s oder Base_d im Debugger schwebe und erweitere, wird das _VPTR auf dothis (msg) und dothat (msg) gesetzt, da diese nicht einmal die gleichen Argumententypen wie Draw_This (ID2D1RENTRETARGE*) und DRAGENTETIGE (ID2D1RAUTRAGE*) und DRAGENTIGE (ID2D1RAUTRAGE*) und DRAGE_THAT (ID2D1RAUTRAGE*) sind, und Draw_That (id2d1r. Mitglied/Typ Casting -Methode funktioniert mit einigen Optimierungen? Ich habe auch versucht, die Basisfunktionen nicht reine Virtuale zu machen, aber das funktioniert auch nicht wie erwartet.
Warum ist die Basisklasse _vptr falsch, wenn sie als später als lpvoid übergeben wird? ⇐ C++
-
- Similar Topics
- Replies
- Views
- Last post