考慮下面的代碼:爲什麼checked_array_iterator在VS2013中不包括<iterator>,但在VS2017中失敗?
#include <memory>
#include <locale>
int main() {
auto source = std::make_unique<int[]>(16);
auto dest = std::make_unique<int[]>(16);
auto dp = stdext::checked_array_iterator<int*>(dest.get(), 16);
std::copy_n(source.get(), 16, dp);
return 0;
}
它通過運行cl.exe /EHsc <file>.cpp
完全編譯上的Visual Studio 2013。然而,在Visual Studio中2017年出現以下錯誤(等等)是由cl.exe
拋出:
vc12.cpp(7): error C2653: 'stdext': is not a class or namespace name
vc12.cpp(7): error C2065: 'checked_array_iterator': undeclared identifier
爲什麼這個代碼不再編譯?
的問題可能是很具體,但在大項目我花了相當長的時間才弄清楚爲什麼它在VS2013上編譯,沒有搜索引擎取得任何結果。 – Lennart
順便說一句,應該是'int main'。 'void main'不是可移植的C++。 –
@BaummitAugen:是的,我儘量保持最小。將添加'int'和'return'。 – Lennart