question about virtual keyword


lets say i have a base with a virtual function. when i implement that function in the derived class many examples dont use the word virtual in the derived class for that fuction. however if i add the word virtual to the derived class virtual function it seems to work the same. is there a difference ?

like the following

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

class test
{
public:
  virtual void test(){}

};


class derived : public test
[
public:

   // whats the difference between this and the one in the comment below
   void test(){}

    // what is different from
   // virtual void test(){} 
   // in this derived class. it seems to do the same wether i 
   // add virtual keyword in derived class or not
};
There is no difference.
ok thanks. i didnt know if it effected inheritance in some way if i derived a third class from derived.
I tested it with a more advanced example using polymorphism and you are correct. as long as the base class defined virtual it didnt matter in the derived class for the same function if it said virtual. both results compiled perfectly and printed out the exact same.
Topic archived. No new replies allowed.