GNU C ++ cannot create a vector of persistent instances of a user class

I have a very simple demo program that compiles well in Microsoft Visual 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;
}

It creates a vector of constant lines. However, in GNU C ++ 4.8.2, it gives a lot of errors that try to say that it is impossible to create a constant vector of String objects. When I replace vector<const String>with vector<String>, it compiles. What is the reason for this behavior of GNU C ++?

+3
source share
2 answers

. , X A, X::value_type A::value_type . X::value_type const String, A::value_type const String. , value_type, " , " ( 27 [allocator.requirements]) const , const undefined.

, , / , , , .

+4

std::vector . , , - -/ noexcept. GCC , . const T std::vector.

+5

All Articles