首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在solaris上排序问题(libCstd)

在solaris上排序问题(libCstd)
EN

Stack Overflow用户
提问于 2011-02-28 09:09:23
回答 2查看 1.6K关注 0票数 1

我在Solaris上遇到了使用Studio编译器的问题,这很可能是由于使用了奇怪的STL实现(libCstd),参见http://developers.sun.com/solaris/articles/cmp_stlport_libCstd.html。考虑到这一点:

代码语言:javascript
复制
std::vector<C*> v;
// .. populate the vector
std::sort(v.begin(), v.end());

其中C是某个类。这会产生以下编译器错误消息:

代码语言:javascript
复制
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm", line 725: Error: The operand "*first" cannot be assigned to.
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm.cc", line 985:     Where: While instantiating "std::__linear_insert<C*const*, C*>(C*const*, C*const*, C**)".
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm.cc", line 985:     Where: Instantiated from std::__insertion_sort<C*const*>(C*const*, C*const*).
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm", line 811:     Where: Instantiated from non-template code.

有谁知道如何绕过这个问题吗?当然,实际上我想使用std::sort与自定义比较函子,但即使这个简单的版本也不起作用。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-28 09:13:18

看来你的实际矢量是const。它是在const成员函数中访问的成员变量吗?这是一个const函数参数吗?

票数 5
EN

Stack Overflow用户

发布于 2011-02-28 09:15:24

代码语言:javascript
复制
#include <algorithm>
#include <vector>

struct C {};

int main()
{
    std::vector<C*> v;
    std::sort(v.begin(), v.end());
}

没有错误地编译

代码语言:javascript
复制
CC: Sun C++ 5.9 SunOS_sparc Patch 124863-19 2009/12/02

被调用为

代码语言:javascript
复制
CC lytenyn.cpp
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5139975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档