there's no vtable in the story if u have no virtuals

say u have 
base::foo(double);
derived::foo(char);

in the object file the compiler generates there will be 2 symbols
base_foo_double
derived_foo_char

so when u call
base *p = new derived;
1) p->foo(double); // call base::foo
2) p->foo(char); // compiler warning i.e trying to pass char to double

in 2) becase foo is NOT virtual this is early binded. so the compiler
inserts code to call base_foo_char when u call 1) or 2)

hope this is clear. better write some tests urself



--- In [email protected], Knowledge Seeker
<[EMAIL PROTECTED]> wrote:
>
> if one don't use 'virtual' with the functions then vtable wont come in 
> existence.
> Then how could this behavior be defined....
> 
> 
> Indika Bandara wrote:
> > the compiler can only guess the function u r calling by its
> > arguments(not even from return type)
> > so when you call derived::f(char) it looks for a function something
> > like derived_f_char(in its symbol table)
> > in essence there will be 2 vtable entries for f(char) and f(double)
> >
> > i think this behavior is very logical in c++.
> >
> > --- In [email protected], Knowledge Seeker
> > <knowledgeseeker78@> wrote:
> >   
> >> Please look into
> >>
> >>
http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
> >>
> >> Could someone describe in more detail why the function of the base
> >>     
> > class 
> >   
> >> is hidden.
> >>
> >> I think  name mangling  should not impose such a restriction, is it 
> >> deliberately made so in C++ language?
> >>
> >>
> >> Cordially,
> >> KnowledgeSeeker
> >>
> >>     
> >
> >
> >
> >
>


Reply via email to