virtual keyword has nothing to do with return type of a method. It only tells that the following method is virtual (you can skip virtual in subclasses).

Try this:
Qt Code:
  1. #include <iostream>
  2.  
  3. class A
  4. {
  5. public:
  6. A() {}
  7. void nonVirt() { std::cerr << "A::nonVirt()" << std::endl; }
  8. virtual void virt() { std::cerr << "A::virt()" << std::endl; }
  9. virtual ~A() {}
  10. };
  11.  
  12. class B : public A
  13. {
  14. public:
  15. void nonVirt() { std::cerr << "B::nonVirt()" << std::endl; }
  16. void virt() { std::cerr << "B::virt()" << std::endl; }
  17. };
  18.  
  19. int main()
  20. {
  21. A a;
  22. B b;
  23. A *ptr = &b;
  24.  
  25. a.nonVirt();
  26. a.virt();
  27. b.nonVirt();
  28. b.virt();
  29. ptr->nonVirt();
  30. ptr->virt();
  31.  
  32. return 0;
  33. }
To copy to clipboard, switch view to plain text mode