d06 check leaks ok

This commit is contained in:
hugogogo
2022-03-14 18:45:24 +01:00
parent 2d613efdf4
commit ac4cb599eb
6 changed files with 100 additions and 40 deletions

View File

@@ -10,18 +10,15 @@ Base * generate() {
srand (time(NULL));
int i = rand() % 3;
if (i == 0)
{
if (i == 0) {
std::cout << "A\n";
base = new A();
}
else if (i == 1)
{
else if (i == 1) {
std::cout << "B\n";
base = new B();
}
else
{
else {
std::cout << "C\n";
base = new C();
}
@@ -47,20 +44,11 @@ void identify(Base* p) {
void identify(Base& p) {
Base base;
try {
base = dynamic_cast<A&>(p);
std::cout << "<A> ";
}
try {base = dynamic_cast<A&>(p); std::cout << "<A> ";}
catch ( std::exception ) {std::cout << "<not A...> ";}
try {
base = dynamic_cast<B&>(p);
std::cout << "<B> ";
}
try {base = dynamic_cast<B&>(p); std::cout << "<B> ";}
catch ( std::exception ) {std::cout << "<not B...> ";}
try {
base = dynamic_cast<C&>(p);
std::cout << "<C> ";
}
try {base = dynamic_cast<C&>(p); std::cout << "<C> ";}
catch ( std::exception ) {std::cout << "<not C...> ";}
std::cout << "\n";
}