hey folks
this is an example taken from a book with regards virtual functions, how =
is it possible to determine if its early or late binding, is the only =
way to look at the assembly of the code?
heres the example:
//: C15:Early.cpp
// Early binding & virtual functions
#include <iostream>
#include <string>
using namespace std;
class Pet {
public:
virtual string speak() const { return ""; }
};
class Dog : public Pet {
public:
string speak() const { return "Bark!"; }
};
int main() {
Dog ralph;
Pet* p1 =3D &ralph;
Pet& p2 =3D ralph;
Pet p3;
// Late binding for both:
cout << "p1->speak() =3D " << p1->speak() <<endl;
cout << "p2.speak() =3D " << p2.speak() << endl;
// Early binding (probably):
cout << "p3.speak() =3D " << p3.speak() << endl;
} ///:~ |