STL map containing references does not compile

Posted by MTsoul on Stack Overflow See other posts from Stack Overflow or by MTsoul
Published on 2010-05-29T06:04:38Z Indexed on 2010/05/29 6:12 UTC
Read the original article Hit count: 255

Filed under:
|
|
|

The following:

std::map<int, ClassA &> test;

gives:

error C2101: '&' on constant

While the following

std::map<ClassA &, int> test;

gives

error C2528: '_First' : pointer to reference is illegal

The latter seems like map cannot contain a reference for the key value, since it needs to instantiate the class sometimes and a reference cannot be instantiated without an object. But why does the first case not work?

© Stack Overflow or respective owner

Related posts about c++

Related posts about stl