GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Jun-2008, 05:15
u_peerless u_peerless is offline
New Member
 
Join Date: Jun 2008
Posts: 7
u_peerless has a little shameless behaviour in the past

Pure Virtual Function - Virtual Method Table


Hi C++ Coders,
Can you please help me regarding one thing.
For pure virtual function, what are the entries created in the virtual method table.
Say I have a program:
CPP / C++ / C Code:
class base
{
   public:
            virtual void display() = 0;
         ...........
};

class derived1:public base
{
  public:
           void display()
            {
               cout<<"Derived1:";
            }
};

class derived2:public derived
{
  public:
           void display()
            {
               cout<<"Derived2:";
            }
};

So here when derived class functions will be called through base class pointer, then how with the help of virtual method table the proper function is calling?
And what are the entries in the 3 vtable for these 3 classes?

And one more query:
To see vtable core dump, is there any compiler flag (g++) in Solaris / Red Hat Linux to be used?

Thanks in advance.

With regards,
u_peerless
Last edited by LuciWiz : 08-Jun-2008 at 16:02. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 06-Jun-2008, 06:07
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Pure Virtual Function - Virtual Method Table


Virtual Table is available for only pure virtual function.

Quote:
then how with the help of virtual method table the proper function is calling?

Basically, virtual table is just sort of array of function pointer.

RTTI helps to investigate the object actual content type.

After investigation, they will just called the correct class for the class.

I hope this help.

Please correct me if i wrong.
  #3  
Old 06-Jun-2008, 07:40
u_peerless u_peerless is offline
New Member
 
Join Date: Jun 2008
Posts: 7
u_peerless has a little shameless behaviour in the past

Re: Pure Virtual Function - Virtual Method Table


Virtual Table is created even if it is not pure virtual function.
I got my answer, I posted this question in another forum. I got reply from them.
cboard.cprogramming.com
Thanks for your reply.
  #4  
Old 06-Jun-2008, 08:46
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 586
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Pure Virtual Function - Virtual Method Table


Quote:
Originally Posted by Peter_APIIT
Virtual Table is available for only pure virtual function.
No. The consequence of declaring pure virtual functions is the compiler will enforce that instances of this type cannot be created.
  #5  
Old 07-Jun-2008, 17:52
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Pure Virtual Function - Virtual Method Table


That's means We cannot create object from abstract class or classes with pure virtual function.

Please post the link here and let other benefits.
  #6  
Old 07-Jun-2008, 17:59
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 586
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Pure Virtual Function - Virtual Method Table


Quote:
Originally Posted by Peter_APIIT
That's means We cannot create object from abstract class or classes with pure virtual function.
Correct. Unless all virtual member functions can be resolved (meaning that valid entries for each virtual member function specified in the vtable...), objects of that type cannot be created. This is why these classes are called abstract.

However, note that pointers to abstract classes can be created.
Quote:
Please post the link here and let other benefits.
All C++ textbooks should mention this fact. If they don't, they aren't worth the paper they are printed upon.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 66 16-Jan-2010 10:53
Flex and bison coding lucky88star C++ Forum 5 24-Dec-2007 11:57
What does =0 in Pure virtual function means? Poolan C++ Forum 4 26-May-2006 14:58
pure virtual function vatsa_mitr C++ Forum 1 12-May-2006 00:41
No output from loop function crystalattice C++ Forum 2 20-Dec-2004 20:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:50.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.