The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ubuntu to pure debian Texasone Linux 13 06-01-2008 09:20 AM
Barcode Writer in Pure Postscript 2008-01-19 (Default branch) iBot Software Releases - RSS News 0 01-19-2008 05:30 PM
Barcode Writer in Pure Postscript 2008-01-01 (Default branch) iBot Software Releases - RSS News 0 01-01-2008 01:40 PM
Where can i get pure unix? Bstyle UNIX for Dummies Questions & Answers 2 12-19-2005 08:13 AM
Sharing C++ Objects with virtual function table pointers Seeker High Level Programming 2 01-26-2002 11:09 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-03-2007
Registered User
 

Join Date: Mar 2007
Posts: 25
Pure Virtual Function in C++

Dear All,
Here I want to know why we put =0 in case of pure virtual function, why not =1, =2 or any thing else
Please send me answer any one as soon as possible.
Reply With Quote
Forum Sponsor
  #2  
Old 06-03-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
History.

If I have a function pointer in C

typedef int (*foo_ptr)(void);
foo_ptr my_foo;

I can either

(a) leave it to be undefined and a danger to all who touch it

(b) set it to point to an implementation of foo()

(c) set it to NULL or (foo_ptr)0 so people can check it's validity.

C++ is derived from C and setting it to 0 is an indication that this class does not provide an implementation of this function.

There are other places where a non-zero initialisation of a pointer is special such as the SIG_IGN/SIG_DFL and _XtInherit.

Unless you are either (a) implementing a C++ compiler (b) answering a homework question, the reason why is not actually important.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0