-3

I have 4 classes in c++ . Animal is the super class were Snake and Tiger inherit from Animal but also inherit from Dangerous Animal . I have implemented a function to check if Snake or tiger is an instance of DangerousAnimal . However I am finding problems in implemting it in c++

my code is :

bool Vet::examine (Animal *someAnimal){

        if(DangerousAnimal* s = dynamic_cast<DangerousAnimal*>(Animal)){
            return false;
        }else{
            return true;
        }
    }

The error is

dillu24@dillu24-VirtualBox:~/Desktop/OOP/Lab1$ g++ -std=c++11 -oAnimalWellBeingLauncher AnimalWellBeingLauncher.cpp q1.cpp
q1.cpp: In member function ‘bool Vet::examine(Animal*)’:
q1.cpp:122:64: error: expected primary-expression before ‘)’ token
   if(DangerousAnimal* s = dynamic_cast<DangerousAnimal*>(Animal)){
  • The code, the code, where is the code! Please provide a [MCVE](http://stackoverflow.com/help/mcve): Minimal (OK) Complete (!!) Verifiable (!!) Example. Your example is neither complete nor verifiable, and therefore you will need multiple round-trips to get your code to compile. – Matthieu M. Oct 29 '16 at 18:47

1 Answers1

2

The syntax of dynamic_cast is dynamic_cast<TargetType>(variable), so you have to write dynamic_cast<DangerousAnimal*>(someAnimal).

Hugal31
  • 1,610
  • 1
  • 14
  • 27