answersLogoWhite

0


Best Answer

A local class refers to a class which has been defined within a function.

For example, consider a function A :

int A(int d)

{

class X

{

int a,b;

void func();

public :

int func2()

{

//do something

}

}

//rest of the function.

}

Class X is local to the function A, and can only be instantiated inside the function A. Use of such functions are usually indicative of poor function design.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

Virtual classes are base classes that are shared between two or more classes which are themselves base classes in a multiple inheritance hierarchy. Consider the following:

struct A {};

struct B : A {};

struct C : A {};

struct D : B, C {};

Class A serves as a common base class for B and C which are inherited by D. Thus class D has two instances of class A. That is; D::B::A and D::C::A are explicit instances of A. This creates ambiguity when implicitly referring to A's members since the compiler cannot determine which instance to refer to. The ambiguity can be eliminated by referring to the explicit instance, however it is often possible for both B and C to share the same instance of A. This is achieved by declaring A as a virtual base class of B and C.

struct A {};

struct B : virtual A {};

struct C : virtual A {};

struct D : B, C {};

When you declare a virtual base class, it automatically becomes a direct ancestor of the most-derived class. The most-derived class is responsible for constructing the virtual class. All classes that inherit from the virtual class then inherit from this single virtual instance.

Thus if you declare an instance of B, B is the most-derived class (so it behaves just as if A were declared non-virtual). But if you declare an instance of D, D becomes the most-derived class.

Ideally, a virtual base class should have no data attributes since its purpose is to provide a common interface to both B and C. If A does have data attributes, keep in mind that modifying the internal state of class A will affect both B and C. Typically, class D will override all virtual methods of class A and coordinate any explicit calls to those overrides in either A, B or C.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are virtual classes in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you implement inheritance in c plus plus?

You implement inheritance by deriving a new class of object from an existing class of object. The existing class is known as the base class of the derived class.Classes declared final cannot be used as bases classes and classes without a virtual destructor (or a virtual destructor override) cannot be used as polymorphic base classes.


What is a virtual base class in C plus plus when the different methods in base and derived classes have the same name true or false?

False. A virtual base class is one that is common to two or more derived classes that are themselves base classes, and that may be combined through multiple inheritance. By declaring the common base class to be virtual in its direct derivatives, only one instance of the common base class exists in the multiple-inheritance classes.


Drawbacks of c plus plus?

Not as commonly used. More schools are replacing their c++ classes with java classes.


How does c plus plus endeavor to represent the object oriented paradigm?

C++ endeavours to represent the object oriented programming paradigm through the use of classes. The four main pillars of OOP are encapsulation, inheritance, polymorphism and abstraction, which C++ primarily achieves through the use of classes, class hierarchies, virtual methods and templates.


Are all C plus plus classes subtypes?

no


What is binding in c plus plus?

Binding refers to classes and their member methods. A class that has no virtual methods can simply be bound to all its methods at compile time. This is known as static binding. However classes with virtual functions require special handling as they can be overridden by derived classes. If the derived class cannot be determined at compile time, then its overridden methods are dynamically bound at runtime, using the virtual table (or v-table) to determine which version of a method must be called.


Why do you need c plus plus?

For programming. C++ is better than C because it is object-oriented and has classes.


What year c plus plus was developed?

Developed in 1979 by the name of C with classes. Renamed to C++ in 1983.


What is diffence between c and c plus plus?

main difference b/w c and c++ is that c is procedural language whereas c++ is object oriented language also classes are not used in c but in c++ classes are used.


What was c plus plus previously called?

'C with Classes' began development in 1979. The name changed to 'C++' in 1983.


Programming codes under classes in c plus plus?

Are called methods.


Does the C plus plus programming language use a virtual machine?

No, it does not. But Microsoft Visual Studio 2008 allows you to connect to a virtual machine and run your projects "sandboxed".