Pure Virtual Function in C++


 
Thread Tools Search this Thread
Top Forums Programming Pure Virtual Function in C++
# 1  
Old 06-03-2007
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.
# 2  
Old 06-03-2007
History. Smilie

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Providing virtual machine priority in kvm based virtual machines

Hi All, Is there any way I can prioritize my VMs when there is resource crunch in host machine so that some VMs will be allocated more vcpu, more memory than other VMs in kvm/qemu hypervisor based virtual machines? Lets say in my cloud environment my Ubuntu 16 compute hosts are running some... (0 Replies)
Discussion started by: SanjayK
0 Replies

2. Programming

Pure C function pointer on printing vowels twice

Have difficulty to understand this pure C code to only print vowels twice from input string. Questions are commented at the end of each place. #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <limits.h> /* *Demonstrate the use of dispatch tables */ /*Print a char... (11 Replies)
Discussion started by: yifangt
11 Replies

3. Solaris

Change hostID of Solaris 10 virtual/guest machine installed by Virtual Box 4.1.12 on Windows-XP host

Trying to set or modify the randomly set hostID of a Solaris 10 virtual/guest machine that I installed on a Windows-XP host machine (using Virtual Box 4.1.12). I was able to set/modify the hostname of the Solaris 10 virtual/guest machine during installation as well as via the Virtual Box... (4 Replies)
Discussion started by: Matt_VB
4 Replies

4. UNIX for Advanced & Expert Users

What is the function to get address of the virtual memory block in linux??

I want address of current virtual memory block? i am using fedora10:wall::wall: (1 Reply)
Discussion started by: powyama
1 Replies

5. UNIX for Dummies Questions & Answers

Have to log out of a virtual terminal twice in order to exit virtual terminals

Not really a newbie, but I have a strange problem and I'm not sure how to further troubleshoot it. I have to log out of a virtual terminal by typing exit, then exit again as in: woodnt@toshiba-laptop ~ $ exit logout woodnt@toshiba-laptop ~ $ exit logout I DON'T have to do this when I'm... (1 Reply)
Discussion started by: Narnie
1 Replies

6. Solaris

Is there any Virtual data center as we have Virtual Machine?

Do we have any Virtual Data Center software as we have Virtual Machine? I want to practice everything of Solaris practically but i don't have resources like data center which includes Servers, Data storages, switches, and other things. (2 Replies)
Discussion started by: karman0931
2 Replies

7. UNIX for Dummies Questions & Answers

Need to check all virtual hostnames/virtual IP's

Hi Folks, I want to check all the virtual hostname's/IP's of a host/ip. Currently we are using HP-UX and open SuSe. Please tell me the command to list out all virtual names of a particular host. many thanks in advance. (2 Replies)
Discussion started by: sai21
2 Replies

8. UNIX for Advanced & Expert Users

Differentiating between Virtual and non Virtual IP addresses

Hello, I would like to know if there is a command or any configuration file to find and differentiate the Virtual IP Addresses (of the Cluster Resource Group) and the IP Address of the Cluster Node. I observe that the ifconfig -a command returns all the IP addresses configured on the ... (1 Reply)
Discussion started by: vineetd
1 Replies

9. Programming

Sharing C++ Objects with virtual function table pointers

I am pondering the next question: Can I safely sare objects that have virtual functions (i.e. have virtual function table pointers) between two processes ? Where will the pointers point to in each process ? What I am afraid of is that in the creating process the pointer will indeed point to... (2 Replies)
Discussion started by: Seeker
2 Replies
Login or Register to Ask a Question