如果我交换两个向量,它们的迭代器是否仍然有效,现在只是指向"其他"容器,或者迭代器是否会失效?
那是,给定:
using namespace std;
vector<int> x(42, 42);
vector<int> y;
vector<int>::iterator a = x.begin();
vector<int>::iterator b = x.end();
x.swap(y);
// a and b still valid? Pointing to x or y?
Run Code Online (Sandbox Code Playgroud)
似乎std没有提到这个:
[n3092 - 23.3.6.2]
void swap(vector<T,Allocator>& x);效果:将*的内容和容量()与x的内容和容量()进行交换.
请注意,因为我在VS 2005上,我也对迭代器调试检查等的影响感兴趣(_SECURE_SCL)
这是一个小测试程序:
#include <iostream>
class Test
{
public:
static void DoCrash(){ std::cout<< "TEST IT!"<< std::endl; }
};
int main()
{
Test k;
k.DoCrash(); // calling a static method like a member method...
std::system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在VS2008 + SP1(vc9)上编译很好:控制台只显示"TEST IT!".
据我所知,不应该在instanced对象上调用静态成员方法.
预编译头文件的最佳候选者是什么?我可以在那里放置STL和Boost标头,即使它们有模板吗?这会减少编译时间吗?另外,减少编译时间的最佳IDE设置是什么?
任何机构都可以告诉我regsvr32和RegAsm有什么区别?我的Dll在C#中,那么如何将类导入到c ++中呢?
该文件的目的是stdafx.h什么,预编译头文件的含义是什么?
所以我可以做点什么
#ifdef MSVC
//do compiler specific code here
#endif
Run Code Online (Sandbox Code Playgroud) 我有类结构定义如下:
#include <limits>
struct heapStatsFilters
{
heapStatsFilters(size_t minValue_ = 0, size_t maxValue_ = std::numeric_limits<size_t>::max())
{
minMax[0] = minValue_; minMax[1] = maxValue_;
}
size_t minMax[2];
};
Run Code Online (Sandbox Code Playgroud)
问题是我不能使用'std :: numeric_limits :: max()'并且编译器说:
Error 8 error C2059: syntax error : '::'
Error 7 error C2589: '(' : illegal token on right side of '::'
我使用的编译器是Visual C++ 11(2012)
我需要安装Visual C++ Build Tools.当我下载安装程序时,我已经尝试安装它,但它告诉我需要卸载VS 2015!
我该如何解决?为什么Visual C++ Build工具告诉我需要删除当前的VS 2015安装?
出于某种原因,我需要暂时禁用头文件中的某些宏,这#undef MACRONAME将使代码编译,但它将取消现有的宏.
有没有一种方法可以禁用它?
我应该提到你并不真正了解宏的值,而且我正在寻找交叉编译器解决方案(至少应该在GCC和MSVC中工作).
在SO上阅读问题,评论和答案,我一直听说MSVC没有正确地实现两阶段模板查找/实例化.
据我所知,到目前为止,MSVC++只对模板类和函数进行了基本的语法检查,并没有检查模板中使用的名称是否至少被声明了或者沿着这些行.
它是否正确?我错过了什么?