的向量我已經編譯好上的Microsoft Visual C++一個非常簡單的演示程序:GNU C++不能創建常量自定義類實例
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
class String
:public wstring
{
public:
String(void)
{
}
String(const String &other)
: wstring(other)
{
}
};
int main(void)
{
vector<const String> v;
v.push_back(String());
printf("Hello, World!");
return 0;
}
它創建的字符串常量的載體。但是,在GNU C++ 4.8.2中,它提供了很多錯誤,試圖說無法創建常量String對象的向量。當我用vector<String>
代替vector<const String>
時,它編譯。 這種GNU C++行爲的原因是什麼?
對於某些操作,類型必須是可賦值的(和/或移動變體)。 'const T'不能滿足這個要求。 – juanchopanza