RAGHU
2009-11-27 09:46:40 UTC
Hi all,
The below example shows a simple virtual function implementation.Where
only base class-"Window" is having a virtual function."Any class
having virtual function a Vtable will be created to that class".
Confusion:
Now I am inheriting the base class-window
class CommandButton : public Window
Now I would like know does for derived class "CommandButton" another
Vtable will be created or not??As you can see there are no virtual
functions in derived class.
class Window // Base class for C++ virtual function example
{
public:
virtual void Create() // virtual function for C++ virtual
function example
{
cout <<"Base class Window"<<endl;
}
};
class CommandButton : public Window
{
public:
void Create()
{
cout<<"Derived class Command Button - Overridden C++
virtual function"<<endl;
}
};
void main()
{
Window *x, *y;
x = new Window();
x->Create();
y = new CommandButton();
y->Create();
}
The output of the above program will be,
Base class Window
Derived class Command Button
Thanks,
RAGHU
The below example shows a simple virtual function implementation.Where
only base class-"Window" is having a virtual function."Any class
having virtual function a Vtable will be created to that class".
Confusion:
Now I am inheriting the base class-window
class CommandButton : public Window
Now I would like know does for derived class "CommandButton" another
Vtable will be created or not??As you can see there are no virtual
functions in derived class.
class Window // Base class for C++ virtual function example
{
public:
virtual void Create() // virtual function for C++ virtual
function example
{
cout <<"Base class Window"<<endl;
}
};
class CommandButton : public Window
{
public:
void Create()
{
cout<<"Derived class Command Button - Overridden C++
virtual function"<<endl;
}
};
void main()
{
Window *x, *y;
x = new Window();
x->Create();
y = new CommandButton();
y->Create();
}
The output of the above program will be,
Base class Window
Derived class Command Button
Thanks,
RAGHU