Can we achieve overriding in STL. If yes then provide me some example and if no then reason. Thanks in advance.
Asked
Active
Viewed 342 times
2 Answers
0
No. Just because stl containers have no virtual functions and it's dangerous to derive from stl container, since it has no virtual destructor (you can specialize stl container for your type, but it's not overriding and it shouldn't be done).

ForEveR
- 55,233
- 2
- 119
- 133
-
Thanks buddy, But my question is can I achieve overriding using own class objects. means after creating the class object type vector, map, list (who have objects instead of value ) – monu Dec 31 '15 at 07:49
0
STL containers have no virtual method hence you cannot override the function which is not virtual.
As an alternative you can use composition and give a interface to your class.
You can also refer to a similar thread: How can I override an C++ standard-library class function?

Community
- 1
- 1

Rahul Tripathi
- 168,305
- 31
- 280
- 331