Results 1 to 4 of 4

Thread: What is virtual keyword and how to implement it in interface using Visual Studio

  1. #1
    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?

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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.

  3. #3
    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.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    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.

Similar Threads

  1. Replies: 2
    Last Post: 16-02-2011, 02:49 PM
  2. Compare Visual Studio 2010 and Visual Web Developer Express
    By Zacharia in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 04:27 AM
  3. Difference between Visual studio 2005 and Visual studio 2008
    By RohanS in forum Software Development
    Replies: 3
    Last Post: 12-06-2009, 10:48 AM
  4. Create Virtual Directory in server via Visual Studio
    By Bartholomew in forum Software Development
    Replies: 4
    Last Post: 19-05-2009, 10:56 AM
  5. difference between Visual Studio 6 & studio 2003
    By yeshwant in forum Software Development
    Replies: 1
    Last Post: 10-04-2009, 10:01 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,876,454.56883 seconds with 16 queries