Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-06-2009
Member
 
Join Date: Nov 2008
Posts: 3,952
What is virtual keyword and how to implement it in interface using Visual Studio

I would like to know what is virtual keyword in Visual Studio C++? How to implement it in interface? I recently saw some code like this:

Code:
class A
{
public:
virtual ~A();
}

class B : public A
{
public:
virtual ~B();
}

class C: public B
{
public:
virtual ~C();
}
I was just thinking why the destructor over here is declared as virtual. Was that required?
Reply With Quote
  #2  
Old 04-06-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: What is virtual keyword and how to implement it in interface using Visual Studio

A base class method is defined as "virtual" if we want it to be overriden. However if you want to avoid this then use "sealed" keyword. You can declare a class method "virtual" but not a class member. A class member may be overriden even though the virtual keyword is used. You may however use "override" keyword to override virtual method.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 04-06-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: What is virtual keyword and how to implement it in interface using Visual Studio

Just to summarize some points to what opaper said:
  • virtual is used when a method is to be defined as virtual.
  • override is used when a method has to override a virtual method.
  • abstract is used with virtual (or override) when a method has to be defined without implementation.
  • final is used with virtual or override to force a method not to be overridden.
Reply With Quote
  #4  
Old 04-06-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: What is virtual keyword and how to implement it in interface using Visual Studio

Visual Studio C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. A virtual function is a member function of a class and is declared with virtual keyword. A virtual function has a different functionality in the derived class and it is resolved at run-time.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is virtual keyword and how to implement it in interface using Visual Studio"
Thread Thread Starter Forum Replies Last Post
Visual Studio 2010: features and changes compared to Visual Studio 2008 BinDs14 Guides & Tutorials 2 16-02-2011 02:49 PM
Compare Visual Studio 2010 and Visual Web Developer Express Zacharia Software Development 5 28-01-2010 04:27 AM
Difference between Visual studio 2005 and Visual studio 2008 RohanS Software Development 3 12-06-2009 10:48 AM
Create Virtual Directory in server via Visual Studio Bartholomew Software Development 4 19-05-2009 10:56 AM
difference between Visual Studio 6 & studio 2003 yeshwant Software Development 1 10-04-2009 10:01 PM


All times are GMT +5.5. The time now is 07:48 PM.