const 到非常量指针模板参数转换

发布于 2024-12-22 03:36:22 字数 378 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坠似风落 2024-12-29 03:36:22

这似乎是 Sun 的 std 库的已知问题

您最好的选择可能是说服代码作者将作业替换为:

p1 = std::make_pair(p2.first, p2.second);

或者在构建时:

std::pair<char*, int> p1(p2.first, p2.second);

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:

p1 = std::make_pair(p2.first, p2.second);

Or at construction time:

std::pair<char*, int> p1(p2.first, p2.second);
孤者何惧 2024-12-29 03:36:22

您确定使用 libstlport 而不是 libCstd 吗?请参阅:https://stackoverflow.com/a/4481452/196844

这绝对是STL实现中的错误。 C++98 标准的第 20.2.2 节“Pairs”为模板构造函数 template提供了模板构造函数 template。 pair(constpair& p),它从 p 的相应成员初始化成员 firstsecond ,根据需要执行隐式转换。

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 members first and second from the corresponding members of p, performing implicit conversions as needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文