Accepting the temporary access address when accessing the address of the element in the <bool> vector
I get a warning only when accessing the address of an element in a bool vector. For a vector of other data types, such as int i, no warnings are received.
eg
vector<bool> boolVect; boolVect.push_back(false); if (boolVect.size() > 0) { cout << &boolVect[0] << endl; } I get a warning "accepting the temporary address" in the instruction "cout <& boolVect [0] <end_;
Can someone clarify?
+6
2 answers
std::vector<bool> (see, for example, http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=98 or Alternative vector <bool>; ). This is a specialization of std::vector<T> , but the individual elements are stored as packed bits. Therefore, you cannot take the address of an individual element. Therefore, it is really annoying.
+13