d06 check leaks ok
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user