我的框架中有一个模板类,它在调试模式下检查时开始报告变量的无效/损坏/ bad_ptr值。但是,当打印到控制台时,变量看起来是正确的。
我发现有四个因素对这种情况很重要:
在下面的示例中,构造函数参数str在检查时应显示为corrupted / invalid / bad_ptr,但会正确打印到控制台。消除上述任何一个因素可以解决问题。
#define _HAS_ITERATOR_DEBUGGING 0
#include <iostream>
#include <string>
#include <fstream>
template <class T>
class Foo
{
public:
Foo(std::string str)
{
std::cout << str << std::endl;
std::ifstream in;
}
};
int main()
{
Foo<int> MyFoo("Hello World");
return 0;
}
我的问题是,这只是一个VS2010错误还是我正在做的事情导致了这个?