Virtual functions and polymorphism

Posted by ritmbo on Stack Overflow See other posts from Stack Overflow or by ritmbo
Published on 2010-03-13T22:27:04Z Indexed on 2010/03/13 22:35 UTC
Read the original article Hit count: 519

Filed under:
|
|

Suppose I have this:

class A
{
    public:
    virtual int hello(A a);
};

class B : public A
{
   public:
   int hello(B b){ bla bla };
};

So, A it's an abstract class.

1)In the class B, I'm defining a method that its suppose overrides the A class. But the parameter it's slightly different. I'm not sure about this, is this correct? Maybe because of polymorphism, this is ok but its rather confusing. 2) If I do: A a = new B;, and then a.hello(lol); if "lol" it's not of type B, then it would give compile error?, and if it's of type A from another class C (class C : public A), what would happend?

I'm confused about the overriding and virtual thing.. all examples I found work with methods without parameters.

Any answer, link, or whatever it's appreciated.

thanks

pd: sorry for my english

© Stack Overflow or respective owner

Related posts about virtual

Related posts about polymorphism