const 到非常量指针模板参数转换
VC10 和 GCC 4.4 接受以下内容,而 Sun Studio 12 不接受:
std::pair<char*, int> p1;
std::pair<char* const, int> p2;
p1 = p2
Sun Studio 12 抱怨:
错误:无法使用 std::pair
初始化 std::pair .
任何想法为什么会发生这种情况以及我如何让 Sun Studio 忽略它。我正在与第三方库合作,仅针对此类事情重写会很痛苦。
VC10 and GCC 4.4 accept the following, while Sun Studio 12 does not:
std::pair<char*, int> p1;
std::pair<char* const, int> p2;
p1 = p2
Sun Studio 12 complains:
Error: Cannot use std::pair<char*const,
int> to initialize
std::pair<char*, int>.
Any ideas why this is happening and how I can get Sun Studio to ignore this. I am working with a third party library, which would be a pain to rewrite just for this sort of thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎是 Sun 的 std 库的已知问题。
您最好的选择可能是说服代码作者将作业替换为:
或者在构建时:
It seems to be a known issue with Sun's std library.
Your best bet may be to convince the author of the code to replace the assignment with:
Or at construction time:
您确定使用 libstlport 而不是 libCstd 吗?请参阅:https://stackoverflow.com/a/4481452/196844
这绝对是STL实现中的错误。 C++98 标准的第 20.2.2 节“Pairs”为模板构造函数
template提供了模板构造函数
template。 pair(constpair& p)
,它从p
的相应成员初始化成员first
和second
,根据需要执行隐式转换。Are you making sure to use libstlport rather than libCstd? See: https://stackoverflow.com/a/4481452/196844
This is definitely an error in the STL implementation. Section 20.2.2, Pairs, of the C++98 Standard provides for the template constructor
template <class U, class V> pair(const pair<U, V>& p)
which initializes membersfirst
andsecond
from the corresponding members ofp
, performing implicit conversions as needed.