C++ std:vector< T>

后端 未结 1 1938
小鲜肉
小鲜肉 2020-12-12 02:05

i have to continue a programm. The programmer before me used the structure a lot:

std:vector< T* const>

He wrote ist in Visual Studio

相关标签:
1条回答
  • 2020-12-12 02:53

    std::vector uses an Allocator to allocate, reallocate, and deallocate memory for its members. The Allocator requirements are only defined for an Allocator X for type T, where T is "any non-const, non-reference object type" (C++11 Table 27). So using a std::vector<T* const> gives you undefined behaviour, because the allocator it uses is not defined for a const element type.

    You're better off fixing this as soon as possible. There are unlikely to be many issues with changing the declarations to std::vector<T*>.

    0 讨论(0)
提交回复
热议问题