Sponsored Content
Full Discussion: Pure Virtual Function in C++
Top Forums Programming Pure Virtual Function in C++ Post 302120069 by porter on Sunday 3rd of June 2007 04:11:07 PM
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.
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
class_part_initialize() 												   class_part_initialize()

Name
  class_part_initialize - Object class method to initialize class part structure fields.

Synopsis
  typedef void (*XtWidgetClassProc)(WidgetClass);
	 WidgetClass subclass;

Inputs
  subclass  Specifies the pointer to a widget class structure.	It is the class that registered this method or a subclass thereof.

Description
  The class_part_initialize() method is registered on the class_part_initialize field of the Object, RectObj, or Core class structure, and is
  called to dynamically initialize any fields in the class part structure of its widget class.

  During class initialization, the class_part_initialize() method for the class and for all its superclasses is called in  superclass-to-sub-
  class  order on the class record.  These procedures do any dynamic initializations necessary to their class's part of the record, including
  resolution of any inherited methods defined in the class.  For example, if a widget class C has superclasses Core,  Composite,  A,  and  B,
  then	the  class  record for C is passed first to Core's class_part_initialize() method.  This resolves any inherited Core methods and com-
  piles the textual representations of the resource list and action table that are defined in the Core class  part.   Next,  the  Composite's
  class_part_initialize()  is  called  to initialize the Composite part of C's class record.  Finally, the class_part_initialize() procedures
  for A, B, and C (in order) are called.  All these methods will be called again if subclass D of class C is initialized, this time  to  ini-
  tialize the various parts of D's class structure.

  The  class_part_initialize() method is chained in superclass-to-subclass order and cannot be inherited.  Classes that do not define any new
  class fields or that need no extra processing for them can set their class_part_initialize field to be NULL.

  See the "Background" section below for more details on when class initialization is performed.

Usage
  The subclass argument to a class_part_initialize() procedure may be the widget class itself, or any subclass of it.  You should cast it  to
  a  pointer to your widget class and use that pointer to access the fields of the class part structure that your class defines.  If you need
  to access the superclass, use the superclass field in the Object, RectObj, or Core class part.  This is shown in the example below.

  The most common usage of the class_part_initialize() method is to handle inheritance of class methods and other fields.  If  you  define  a
  class  with  a  method  or  other field that can be inherited, you should define a special value that the writer of the subclass can use to
  inherit the field (use the constant _XtInherit cast to the appropriate type, as shown in the example below) and provide  a  class_part_ini-
  tialize() method which checks the inheritable field for this special value and overwrites it with the contents of the superclass's field.

Example
  The  following  procedure is the class_part_initialize() method for the Xaw Form widget class.  Note how it determines the immediate super-
  class and handles the inheritance of the Form layout() class method.

  Note that it does not initialize the Core, Composite, or Constraint class part fields, nor does it make any assumptions about  its  Widget-
  Class argument except that it is a subclass of Form.	Also note that when this method is called for the Form widget class itself, the vari-
  able super will be set to the superclass of Form, which cannot correctly be cast to FormWidgetClass.	This is a bug, but will  never	cause
  problems, because the Form class itself will never have to inherit any fields.

  Note	that the identifier class is a reserved word in C++, and your code will be more portable if you avoid using it as an argument name in
  C code.

     static void ClassPartInitialize(class)
	 WidgetClass class;
     {
	 register FormWidgetClass c = (FormWidgetClass)class;
	 register FormWidgetClass super = (FormWidgetClass)
	     c->core_class.superclass;

	 if (c->form_class.layout == XtInheritLayout)
	     c->form_class.layout = super->form_class.layout;
     }

  The constant XtInheritLayout is defined as follows (in <X11/Xaw/FormP.h>):

     #define XtInheritLayout ((Boolean (*)())_XtInherit)

Background
  All widget classes, whether or not they have class and class part initialization procedures,	must  start  with  their  class_inited	field
  False.

  The  first  time  a  widget  of a class is created, XtCreateWidget() ensures that the widget class and all superclasses are initialized, in
  superclass-to-subclass order, by checking each class_inited field.  If this field is False, XtCreateWidget() calls  the  class_initialize()
  and  the  class_part_initialize()  methods  for  the	class  and all its superclasses.  The Intrinsics then set the class_inited field to a
  nonzero value.  After the one-time initialization, a class structure is constant.  This initialization can also  be  performed  explicitly,
  without creating a widget, by calling XtInitializeWidgetClass().

See Also
  XtInitializeWidgetClass(1),
  Core(3),
  class_initialize(4), initialize(4).

Xt - Intrinsics Methods 												   class_part_initialize()
All times are GMT -4. The time now is 02:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy