Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HO can you sort a const vector
- #include <vector>
- class Foo
- {
- public:
- // clients can't change this vector directly
- const std::vector<int>& get_vector() const { return _vec; }
- // you can still create an interface that allows
- // mutation of the vector in a safe way, or mutate
- // the vector internally.
- void push_back( int i ) { _vec.push_back( i ); }
- private:
- std::vector<int> _vec;
- }
- const std::vector< Foo* > v; // hypothetical declaration
- std::vector< Foo* >* vPtr = const_cast< std::vector< Foo* >* >(&v);
- // GOOD LUCK
- (*vPtr)[0] = new Foo();
Add Comment
Please, Sign In to add comment