Linked Questions

16 votes
2 answers
6k views

I encountered this problem maintaining a port for a large (relative to the size of our team) project, but it was simple to create a small example. stackoverflow.cpp: #include<iostream> #include&...
01d55's user avatar
  • 1,912
9 votes
4 answers
19k views

The following doesn't compile (very verbose error, but basically "cannot be overloaded" and "invalid conversion from 'const void*' to 'void*'"). I can understand why for example push_back() may not ...
Agrim Pathak's user avatar
  • 3,217
11 votes
1 answer
7k views

push_backing to a vector of non-const elements works as expected: std::vector<int> foo; int bar = 0; foo.push_back(bar); But why is the following not possible? std::vector<const int> foo;...
flogram_dev's user avatar
13 votes
0 answers
4k views

What is the rationale behind C++11 forbidding containers of const elements? I am referring to the following error message, which you get if you define, for example, a vector of const elements: error ...
chris's user avatar
  • 319
0 votes
0 answers
544 views

As this answer said: The component type of containers like vectors must be assignable. References are not assignable (you can only initialize them once when they are declared, and you cannot make ...
shengguo lu's user avatar
0 votes
0 answers
245 views

I want to make a vector of const pointers. (the pointers being constant, not A being constant) This code here gives me the error: class A{}; std::vector<A * const> vec; //creates vector of ...
macco's user avatar
  • 489
4 votes
0 answers
113 views

First of all: I'm still a beginner in c ++, but I don't really understand the following: So someone said to me, that if i have for example a container of references (e.g. map), it is not working ...
Avva's user avatar
  • 170
3 votes
0 answers
127 views

The standard library vector prevents us from constructing a vector of consts. My question is why? I read the answers on apparently similar questions to mine and I'm not really convinced. So let's dig ...
Soulimane Mammar's user avatar
5 votes
0 answers
92 views

I have a class with std::set<const std::string> members which compiles fine in Clang 10.0.1 on macOS, but does not with GCC 5.4.0. MRE below #include <set> #include <string> class ...
oarfish's user avatar
  • 4,764
0 votes
0 answers
39 views

vector<const int>() fails to compile in C++14 (and in C++03). Under C++03, we can say const int is not CopyAssignable, so naturally it fails. However, under C++14, the wording in the standard ...
FunkyBaby's user avatar
  • 565
68 votes
4 answers
81k views

Does const vector<A> mean that its elements are constas well? In the code below, v[0].set (1234); in void g ( const vector<A> & v ) produces the compiler error const.cpp:28:3: ...
cibercitizen1's user avatar
49 votes
2 answers
25k views

I have declared the following in my code vector <const A> mylist; I get the following compile error - new_allocator.h:75: error: `const _Tp* __gnu_cxx::new_allocator<_Tp>::address(...
Satabdi's user avatar
  • 642
8 votes
3 answers
6k views

See the code below - I am trying to put a const object into a vector. I know the answer is "STL containers require objects to be assignable and copy constructable", but, without citing the standard, ...
David Doria's user avatar
  • 10.4k
6 votes
3 answers
2k views

After scratching my head at some errors in some template code that used std::vector::value_type I tracked it down to the following. Is this correct behavior according to the standard, or is this a ...
Brandon's user avatar
  • 752
8 votes
3 answers
6k views

It seems to me there should be four variants of boost::optional optional<Foo> => holds a mutable Foo and can be reassigned after initialization optional<Foo const> const => holds a const ...
HostileFork says dont trust SE's user avatar

15 30 50 per page