c++ - vector of const pointers? -
this question has answer here:
- does c++11 allow vector<const t>? 3 answers
the following doesn't compile (very verbose error, "cannot overloaded" , "invalid conversion 'const void*' 'void*'"). can understand why example push_back() may not compile, can't copy/move foo* const, why doesn't compile:
#include <vector> using namespace std; class foo; int main() { vector<foo* const> vec; }
the vector container requires elements copy assignable. because elements guaranteed stored contiguously in memory. if exceed capacity, new chunk has allocated , elements re-assigned. cannot const elements.
same error if try std::vector<const int>, or in fact const type.
Comments
Post a Comment