I am getting the warning only while accessing address of element in vector of bool.
For vector of other data types like int i don’t get any warning.
eg
vector<bool> boolVect;
boolVect.push_back(false);
if (boolVect.size() > 0) {
cout << &boolVect[0] << endl;
}
I get warning “taking address of temporary” at statement “cout << &boolVect[0] << endl;”
Can someone please clarify?
std::vector<bool>is broken (see e.g. http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=98 or Alternative to vector<bool>). It’s a specialization ofstd::vector<T>, but the individual elements are stored as packed bits. Therefore, you can’t take the address of an individual element. Therefore, it’s really annoying.