我在重载 operator<<以与我的地图中的映射值一起使用时遇到问题:
map<string,abs*> _map;
// that my declaration, and I have filled it with keys/values
我试过这两个:
std::ostream& operator<<(std::ostream& os, abs*& ab)
{
std::cout << 12345 << std::endl;
}
std::ostream& operator<<(std::ostream& os, abs* ab)
{
std::cout << 12345 << std::endl;
}
在我的程序中,我只是调用:
std::cout << _map["key"] << std::endl;
// trying to call overloaded operator for mapped value
// instead it always prints the address of the mapped value to screen
我也试过:
std::cout << *_map["key"] << std::endl;
// trying to call overloaded operator for mapped value
// And that gives me a really long compile time error
任何人都知道我可以改变什么来让它输出映射值的值,而不是地址?
任何帮助表示赞赏