Noah Roberts wrote:
festiv wrote:
I want to learn how the compiler is implementing the dynamic binding.
where can i read about this subject (the hole process).
C++ uses static binding so it becomes rather difficult to describe how
it does dynamic binding. You can't say how something does a thing it
does not do :P
Noah,
How do you define "dynamic binding?" I've always understood the term to
mean something like "resolving a member function call at run time rather
than compile time." I would have said C++ supports dynamic binding with the
"virtual" keyword.
festiv,
If you want to know how your compiler implements virtual member functions,
then for a definitive answer you'd have to ask the people who made your
compiler. The C++ standard doesn't require any particular implementation,
although I suspect all real C++ compilers use some sort of "vtable" approach
(see link below).
One of my former professors has some lecture notes online that might
interest you. I think they'll give you an idea of what's probably happening
behind the scenes:
http://www.libertysoft.com/ggu/cis30...ymorphism.html
Unfortunately, I think his second-to-last code example has a couple of
typos. The Manager class' constructor should probably look like this:
Manager::Manager(EmployeeID const&id, StoreID const&store,
double payrate) : Employee(id, store, payrate, polys_)
{
}
or maybe
Manager::Manager(EmployeeID const&id, StoreID const&store,
double payrate) : Employee(id, store, payrate, &polys_)
{
}
depending on whether the Employee class' constructor takes a pointer to a
Polymorphics struct or a reference to a Polymorphics struct.
And the AssistantManager class' constructor should probably look something
like this:
AssistantManager::AssistantManager(EmployeeID const&id, StoreID
const&store, double payrate) : Employee(id, store, payrate, polys_)
{
}
or maybe
AssistantManager::AssistantManager(EmployeeID const&id, StoreID
const&store, double payrate) : Employee(id, store, payrate, &polys_)
{
}
--
Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.