Strange problem with dynamic cast C++
<p>I'm just new to C++, and doing a small project which implementing some inheritance. It can basically be summarized below:</p>

<pre><code>//.h file
class Food{
public:
 Food();
 virtual ~Food();
};

class Animal{
public:
 Animal();
 virtual ~Animal();
 virtual void eat( Food f);
};

class Meat : public Food{
public:
 Meat();
 ~Meat();
};

class Vegetable : public Food{
public:
 Vegetable();
 ~Vegetable();
};

class Carnivore : public Animal{
public:
 Carnivore();
 ~Carnivore();
 void eat(Food f);
};

//.cpp file

Food::Food()
{
do something;
}

Food:~Food()
{
do something;
}

Animal::Animal()
{
do something;
}

Animal::~Animal()
{
do something;
}

Meat::Meat()
{
do something;
}

Meat::~Meat()
{
do something;
}

Vegetable::Vegetable()
{
do something;
}

Vegetable::~Vegetable()
{
do something;
}

Carnivore::Carnivore()
{
do something;
}

Carnivore::~Carnivore()
{
do something;
}

void Carnivore::eat(Food f)
{
 Meat* m = dynamic_cast&lt;Meat*&gt;(&amp;f); 
 if(m != 0) cout &lt;&lt; "can eat\n";
 else cout &lt;&lt; "can not eat\n";
}

//main.cpp

int main()
{
Animal* a;
Food* f;

Meat m;
Vegetable v;
Carnivore c;

a = &amp;c;
f = &amp;v;
a-&gt;eat(*f);
f = &amp;m;
a-&gt;eat(*f);


return 1;
}
</code></pre>

<p>And the output:</p>

<pre><code>can not eat
can not eat
</code></pre>
