std :: vector <const int =“”>未定义的行为?

时间:2018-05-14 14:43:59

标签: c++ vector const

阅读this post后,我尝试了这个

#include <iostream>
#include <vector>

int main()
{
    const int x = 5;
    // x = 200;           Not possible, of course.

    std::vector<const int> xVector = { 5 };
    xVector[0] = 200;

    std::cout << xVector[0];   // 200, no surprise.
}

这在Visual Studio 2017中编译。但这种行为是否在UB中未定义?

红利问题:std::vector<const int>不仅仅是不可修改int的向量的技术原因是什么?

0 个答案:

没有答案
相关问题