I had been requested within an interview that what's the use of virtual keyword having a class declaration in C++ and that i clarified that virtual keyword can't be combined with a category declaration in C++. The interviewer stated that it's possible and requested me to check it later.

Since I've checked it myself I have started to realize that you could do which is not really a compiler error. Actually, after i make a move such as this having a Visual C++ compiler:

virtual class Test
{
   int i;
};

I recieve a compiler warning "warning C4091: 'virtual ' : overlooked on left of 'Test' when no variable is declared". I've not had the opportunity to discover yet that what this warning means and additional what's the use of virtual keyword. If there's no useful usage, then why permitted to begin with why is this not really a compiler error.

This is a bug in VC++. Comeau and gcc both reject the code.

You just can't use virtual for any class. It only works best for member functions

virtual may be used when drawing from another class:

class Foo : public virtual Bar
{
}

This really is accustomed to avoid getting multiple versions of the identical base class when utilizing multiple inheritance. Wikipedia includes a piece of content about them.

Maybe he was mentioning to virtual inheritance / virtual base classes? E.g.

class A : virtual public B
{ ... }

That will technically participate the course definition.

You are searching in the wrong kind of usage - I am confident the interviewer was mentioning to virtual base class terms, like so:

  class A : virtual public B, public C {
    ...
  };

This can be a common idiom and accustomed to circumvent the "multiple base class" scenario in gemstone-formed inheritance trees. The normal trouble with them is you inherit from both class B and sophistication C plus they share the most popular ancestor A. Should you go 'up' the inheritance tree you'll hit the ambiguity regarding which demonstration of 'A' you are designed to use. If B &lifier C possess a like a virtual base class rather, they'll make reference to exactly the same demonstration of A, which solves this issue.

You'll find a far more thorough description with class diagrams here.

Could he happen to be speaking about utilizing a virtual base class within the class declaration?

Such as this:

class CashierQueue : virtual public Queue {};

This really is utilized in multiple inheritance when you wish to prevent a derived class getting multiple copies from the member data if this gets from several classes that share exactly the same base class.

class Queue {};
class CashierQueue : virtual public Queue {};
class LunchQueue : virtual public Queue {};
class LunchCashierQueue : public LunchQueue, public CashierQueue {};

See http://msdn.microsoft.com/en-us/library/wcz57btd(VS.80).aspx