从STL容器继承实现而不是委托可以吗?
class MyContainer : public std::vector<MyObject>{public:
// Redeclare all container traits: value_type, iterator, etc...
// Domain-specific constructors
// (more useful to the user than std::vector ones...)
// Add a few domain-specific helper methods...
// Perhaps modify or hide a few methods (domain-related)};编辑:
// non_api_header_file.hnamespace detail{
typedef std::vector<MyObject> MyObjectBase;}// api_header_file.hclass MyContainer : public detail::MyObjectBase{
// ...};编辑2:
typedef std::vector<MyObject> MyCollection;void specialCollectionInitializer(MyCollection& c, arguments...);result specialCollectionFunction(const MyCollection& c);etc...
typedef std::vector<MyObject> MyCollection;class MyCollectionWrapper{public:
// Constructor
MyCollectionWrapper(arguments...) {construct coll_}
// Access collection directly
MyCollection& collection() {return coll_;}
const MyCollection& collection() const {return coll_;}
// Special domain-related methods
result mySpecialMethod(arguments...);private:
MyCollection coll_;
// Other domain-specific member variables used
// in conjunction with the c
跃然一笑
慕斯王
随时随地看视频慕课网APP
相关分类