Sponsored Content
Top Forums Programming Size of derived class, in case of multiple inheritance Post 302889409 by Corona688 on Thursday 20th of February 2014 11:07:38 AM
Old 02-20-2014
'virtual' means, 'keep a record inside the class for which function I should call'. Otherwise, the compiler doesn't know anything except the type of the variable/pointer.

For example:

Code:
class Base1
{
 public:
  void f() {  }
};

class Derived : public Base1
{
 public:
  void f() {  }
};

main() {
        Base1 *p=new Derived();
        p->f(); // Without virtual, it calls Base1's f()
}

Adding virtual allows it to remember that f() was overloaded / replaced. This memory takes a little space.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do I make multiple connections to the server in this case

Given the following code #!/usr/bin/perl -w use IO::Socket; my($handle, $line, $kidpid); $handle = IO::Socket::INET->new( PeerAddr =>"64.22.229.139", PeerPort =>"4321", Proto=>"tcp", ... (0 Replies)
Discussion started by: frequency8
0 Replies

2. Shell Programming and Scripting

multiple case

hi all im working in tcsh shell. In sh shell i write for example: case in $www 1 | 2 | 3) arguments;; 4 | 5 | 6) arguments;; esac can anybody tell me the equivalent to tcsh of 1 | 2 | 3)? (2 Replies)
Discussion started by: micromicrin
2 Replies

3. Programming

How to make a function friend to both base and derived class

Hi, I have a base class and derived a class from the base class, i want to print & read the data for the object created for the derived class,so i have overloaded both the << and >> operators and also have done the foward declaration. Below is the code snippet, #include <iostream> class... (3 Replies)
Discussion started by: ennstate
3 Replies

4. Shell Programming and Scripting

Multiple conditions in a CASE statement

is it possible to use multiple conditions in a CASE statement? And if so, what is the syntax? I'm trying to use one but can't seem to get it right. I want the statement to be CASE $vendor OR $alias condition 1) statements; condition 2) statements; etc. esac but I keep... (25 Replies)
Discussion started by: Straitsfan
25 Replies

5. Shell Programming and Scripting

Choose multiple conditions in case?

Hi all, I am attempting to create a shell script to optimize some routine process. I want this script can let user select the actions they want to do. But I met a problem that my script can only read one input and then do one action. Is it possible to let my script to run more than one... (2 Replies)
Discussion started by: kaiya
2 Replies

6. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies

7. Programming

Difference in multiple inheritance and multilevel inheritance: same method name ambiguity problem

Hi, In multi-level inheritance: class A { public: void fun() { cout << "A" << endl; } }; class B : public A { public: void fun() { cout << "A" << endl; } }; class C : public B { }; int main() { C c; c.fun(); // Ans: A } (1 Reply)
Discussion started by: royalibrahim
1 Replies

8. Programming

Size of Derived class, upon virtual base class inheritance

I have the two class definition as follows. class A { public: int a; }; class B : virtual public A{ }; The size of class A is shown as 4, and size of class B is shown as 16. Why is this effect ?. (2 Replies)
Discussion started by: techmonk
2 Replies

9. Programming

C++ : Base class member function not accessible from derived class

Hello All, I am a learner in C++. I was testing my inheritance knowledge with following piece of code. #include <iostream> using namespace std; class base { public : void display() { cout << "In base display()" << endl; } void display(int k) {... (2 Replies)
Discussion started by: anand.shah
2 Replies
Creator(3U)                                                 InterViews Reference Manual                                                Creator(3U)

NAME
Creator - recreates catalog-managed objects from disk and instantiates component views from their class identifiers SYNOPSIS
#include <Unidraw/creator.h> DESCRIPTION
A creator object can reconstruct a catalog-managed object from disk and can instantiate a component view given a class identifier. Gener- ally only the Catalog class uses the creator to reconstruct objects from disk, but it may be useful for other classes (e.g., the Component base class) to use the creator to create views of component subjects. Applications that derive new catalog-managed classes or component views must also derive a subclass of Creator that extends the base class operations to support the new classes. PUBLIC OPERATIONS
Creator() Instantiate an new creator object. The Catalog constructor requires an instance of a creator object, either an instance of the Cre- ator base class or an instance of an application-specific Creator subclass. virtual void* Create( ClassId, istream& in, ObjectMap* objmap, int objid ) Create an instance of the class corresponding to the given class identifier. Normally this operation will be used by the Catalog class exclusively. This operation contains a switch statement that calls a CREATE macro for each possible class identifier. The CREATE macro takes the istream, ObjectMap, and int arguments as parameters; it is not important to understand how the macro uses these arguments. For example, the entry for the LineComp line component subject class is case LINE_COMP: CREATE(LineComp, in, objmap, objid); Derived Creator classes must redefine this operation to include a switch statement for application-specific classes, with the default case calling the parent class's Create operation. virtual void* Create(ClassId id) Create an instance of the view class corresponding to the given view class identifier. This operation is implemented with a set of consecutive if statements of the form if (id == <identifier name>) return new <class name>; For example, the entry for the PostScript external view class identifier for line components is if (id == PS_LINE) return new PSLine; Derived Creator classes must redefine this operation to include if statements for application-specific view classes, with the final statement being a call to the parent classes's Create operation. SEE ALSO
Catalog(3U), classes(3U), globals(3U) Unidraw 12 June 1990 Creator(3U)
All times are GMT -4. The time now is 12:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy