3 Replies - 6114 Views - Last Post: 17 October 2007 - 02:58 AM Rate Topic: -----

#1 BrainStew  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 154
  • Joined: 02-August 07

Virtual Keyword

Post icon  Posted 16 October 2007 - 09:11 AM

Just to clarify, is this descriptioin of the virtual keyword correct?

Virtual allows you to call methods in a derived class when there is a method in that derived classes base class with the same name? Something along those lines?

thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Virtual Keyword

#2 BrainStew  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 154
  • Joined: 02-August 07

Re: Virtual Keyword

Posted 16 October 2007 - 12:05 PM

bump. I know thats not all it does, I need help with a better description.

Cheers
Was This Post Helpful? 0
  • +
  • -

#3 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 855
  • View blog
  • Posts: 2,338
  • Joined: 20-August 07

Re: Virtual Keyword

Posted 17 October 2007 - 02:48 AM

Not simply with the same name, but with the same signature. Consider the following
class Base
{
public:
	virtual void my_method();
	void my_method(int);
};

class Derived
{
public:
	void my_method();
	void my_method(int);
}; 

In the above example, only my_method() may be used polymorphically. any calls issued to my_method(int) will still use the base class method.
Was This Post Helpful? 0
  • +
  • -

#4 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 855
  • View blog
  • Posts: 2,338
  • Joined: 20-August 07

Re: Virtual Keyword

Posted 17 October 2007 - 02:58 AM

NB: The virtual keyword may also be used with inheritance, (termed 'virtual inheritance') in order to allow a class to derive from multiple bases with conflicting implementations (Often referred to as 'the diamond problem' where two derived classes of a base class are themselves used as base classes in Multiple Inheritance). The implementation of a class which is inherited virtually may be overridden by the implementation inherited from another class.

This post has been edited by Bench: 17 October 2007 - 03:03 AM

Was This Post Helpful? 1

Page 1 of 1