本文介绍了solaris上的std :: sort问题(libCstd)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Sun Studio编译器的Solaris上有一个问题,这很可能是由于使用了奇怪的STL实现( libCstd ),参见。请考虑这个:

I have a problem on Solaris using the Sun Studio compiler, which is most likely due to the strange STL implementation (libCstd) used, see http://developers.sun.com/solaris/articles/cmp_stlport_libCstd.html. Consider this:

std::vector<C*> v;
// .. populate the vector
std::sort(v.begin(), v.end());

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

where C is some class. This produces the following compiler error message:

"/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 ,但即使这个简单的版本也不起作用。

Does anybody know how to circumvent the problem? Of course, actually I want to use std::sort with a custom comparison functor, but even this simple version does not work.

推荐答案

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

Looks like your actual vector is const. Is it a member variable accessed in a const member function? Is it a const function argument?

这篇关于solaris上的std :: sort问题(libCstd)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:33