chr*_*umb 3 c++ hp-ux stdstring
任何有关这方面的想法将不胜感激:
std::string s1 = "hello";
std::string s2 = std::string(s1);
Run Code Online (Sandbox Code Playgroud)
我现在期望这两个字符串是独立的,即我可以将",world"附加到s2,而s1仍然会读取"hello".这是我在Windows和Linux上发现的但是在HP_UX机器上运行代码似乎s2和s1是相同的字符串,所以修改s2会改变s1.
这听起来绝对疯狂,有人见过类似的东西吗?
虽然我无法重现OP的确切错误,但我在HP-UX aCC编译器中遇到了类似的错误.我在HP主板上发布了它,最终得到了HP的回复.基本上他们的版本3.xx(3.70,3.73,3.67等)的aCC搞砸了std :: string构造.我们不得不转向6.xx版本的编译器.我们当时遇到的问题是PA-RISC机器没有6.xx编译器,只有安腾.我相信2007年9月为PA-RISC发布了6.xx编译器.
提出问题的代码是:
#include <iostream>
#include <string>
class S : public std::string // An extension of std::string
{
public:
explicit S(const char* s)
: std::string(s)
{
}
};
class N // Wraps an int
{
public:
explicit N(int n)
: _n(n)
{}
operator S() const // Converts to a string extension
{
return _n == 0 ? S("zero") : (_n == 1 ? S("one") : S("other"));
}
private:
int _n;
};
int main(int, char**)
{
N n0 = N(0);
N n1 = N(1);
std::string zero = n0;
std::cout << "zero = " << zero << std::endl;
std::string one = n1;
std::cout << "zero = " << zero
<< ", one = " << one << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是打印:
零=
零零=一,一=一
换句话说,从n1构造字符串1完全破坏了另一个字符串(字符串零).
注意:
要查看编译器的版本,请键入"aCC -V"
要查看计算机类型,请键入"uname -m"(9000/800 ==> PA-RISC,ia64 ==> Itanium)