Not 100% sure when to use virtual methods in base class

This is a discussion on Not 100% sure when to use virtual methods in base class within the C++ Programming forums, part of the General Programming Boards category; I have a few base classes, and I have derived classes deriving from both bases at the same time. Do ...

  1. #1
    Banned
    Join Date
    Jan 2003
    Posts
    1,708

    Not 100% sure when to use virtual methods in base class

    I have a few base classes, and I have derived classes deriving from both bases at the same time. Do I use virtual methods only when I plan on overriding those mehods in the derived classes? I have at least a few methods that are just straight inheritance, the derived classes don't need to override them therefore I did not make them virtual. am I on the right track?

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    only use them when you intend on performing some "unknown" method with a base class pointer. Otherwise you are wasting the time that it takes to dereference a pointer from a v_ptr table
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    I tend to make it a rule to make any function that may be implemented differently by a child class virtual. So basically I say yes, you are on the right track.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual base class constructor
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2008, 03:18 AM
  2. Replies: 4
    Last Post: 12-29-2002, 12:29 AM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21