Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Template problem
Re: Template problem [message #14323 is a reply to message #14320] |
Fri, 22 February 2008 14:58 |
bytefield
Messages: 210 Registered: December 2007
|
Experienced Member |
|
|
waxblood wrote on Fri, 22 February 2008 15:32 | I remember Mirek once said somewhere in the forum that inheriting classes from upp containers is discouraged, as it is with STL... . Maybe problems arise just because STL is not designed to do such operations, but I can't tell more.
David
|
Yeah i know it's not a good behavior but in that case(it was an example from Bjarne C++ programming book) std::vector doesn't raise any exception if you use [] operator over the vector limits and it could result in segmentation fault. So a solution to this problem is to inherit from vector and in new [] operator use return vector::at(i) which raise an exception if i is out of vector limits(see first example).
Sometimes is useful to inherit from containers[ex. if you want to make some gui stuff(ex. sizers) and cannot keep container as member].
cdabbd745f1234c2751ee1f932d1dd75
|
|
|
Goto Forum:
Current Time: Fri Apr 19 05:57:58 CEST 2024
Total time taken to generate the page: 1.08795 seconds
|