S
Simon Elliott
For some time I've been using typedefs for STL containers for reasons
outlined in:
http://www.gotw.ca/gotw/046.htm
However a major downside to this is that you can't forward declare a
typedef of a STL container:
#include <vector>
struct foo
{
int f1;
};
typedef std::vector<foo> fooVector;
// Can't forward declare fooVector
However, by deriving a class from the container, it becomes possible to
forward declare it:
class fooVector
ublic std::vector<foo>{};
This appears to allow me to treat fooVector as a std::vector<foo> and
to forward declare it:
class fooVector; // OK
In general it's not recommended to inherit from STL containers because
they don't have virtual destructors. Am I correct in thinking that the
above usage is safe because I'm not dealing with the fooVector class
polymorphically?
Is there any way to improve on the above so that other developers don't
inadvertantly use fooVector in a dangerous manner?
outlined in:
http://www.gotw.ca/gotw/046.htm
However a major downside to this is that you can't forward declare a
typedef of a STL container:
#include <vector>
struct foo
{
int f1;
};
typedef std::vector<foo> fooVector;
// Can't forward declare fooVector
However, by deriving a class from the container, it becomes possible to
forward declare it:
class fooVector
This appears to allow me to treat fooVector as a std::vector<foo> and
to forward declare it:
class fooVector; // OK
In general it's not recommended to inherit from STL containers because
they don't have virtual destructors. Am I correct in thinking that the
above usage is safe because I'm not dealing with the fooVector class
polymorphically?
Is there any way to improve on the above so that other developers don't
inadvertantly use fooVector in a dangerous manner?