Skip to content

Instantly share code, notes, and snippets.

@qrealka
Last active January 24, 2017 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qrealka/11e499e1fb8634f5315c9b412d08b0eb to your computer and use it in GitHub Desktop.
Save qrealka/11e499e1fb8634f5315c9b412d08b0eb to your computer and use it in GitHub Desktop.
test virtual
#include <iostream>
using namespace std;
struct A1
{
virtual void Test() = 0;
virtual ~A1()
{
std::cout << "~A1\n";
}
};
struct A2
{
A1* const m_a1;
A2(A1* a1) : m_a1(a1) {}
bool IsTest() const { return true; }
virtual ~A2()
{
std::cout << "~A2\n";
if (m_a1 && IsTest())
{
m_a1->Test();
}
}
};
struct B1
: public A2
, private A1
{
B1() : A2(this) {}
void Test() override
{
std::cout << "B1::Test\n";
}
};
int main()
{
A2* b1 = new B1();
delete b1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment