05-02-2011, 06:34 PM
Virtual inheritance is a type of inheritance in which the part of the object that belongs to virtual base class becomes common direct base class for derived class and any other class that derives from it. Virtual inheritance is used in multiple inheritance.
Virtual inheritance example in c++:
class Animal{
public:
virtual void eat();
};
// Two classes virtually inheriting Animal:
class Mammal : public virtual Animal {
public:
virtual void walk();
};
class WingedAnimal : public virtual Animal {
public:
virtual void flap();
};
// A bat is a winged mammal
class Bat : public Mammal, public WingedAnimal
{
};
Generic algorithms are those algorithms that are independent of data structures. This can be achieved using Generic Programming in which a function works for all types of containers.
Example:
template void Swap(T & a, T & b) //"&" passes parameters by reference
{
T temp = b;
b = a;
a = temp;
}
string hello = "world!", world = "Hello, ";
Swap( world, hello );
cout << hello << world << endl;
//Output is "Hello, world!"
Virtual inheritance example in c++:
class Animal{
public:
virtual void eat();
};
// Two classes virtually inheriting Animal:
class Mammal : public virtual Animal {
public:
virtual void walk();
};
class WingedAnimal : public virtual Animal {
public:
virtual void flap();
};
// A bat is a winged mammal
class Bat : public Mammal, public WingedAnimal
{
};
Generic algorithms are those algorithms that are independent of data structures. This can be achieved using Generic Programming in which a function works for all types of containers.
Example:
template void Swap(T & a, T & b) //"&" passes parameters by reference
{
T temp = b;
b = a;
a = temp;
}
string hello = "world!", world = "Hello, ";
Swap( world, hello );
cout << hello << world << endl;
//Output is "Hello, world!"
0300-9520262
Get solution in 24 hour |cpmputer & internet
mileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
