Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 目视检漏仪未发现泄漏VS2013_C++_Visual Studio_Memory Leaks_Visual Leak Detector - Fatal编程技术网

C++ 目视检漏仪未发现泄漏VS2013

C++ 目视检漏仪未发现泄漏VS2013,c++,visual-studio,memory-leaks,visual-leak-detector,C++,Visual Studio,Memory Leaks,Visual Leak Detector,我似乎无法让VLD捕捉任何内存泄漏,无论我如何尝试。你知道为什么吗 这里也是输出的一个片段: Visual Leak Detector Version 2.4RC2 installed. The thread 0x5748 has exited with code 0 (0x0). The thread 0x2c70 has exited with code 0 (0x0). The thread 0x3c98 has exited with code 0 (0x0). No memory l

我似乎无法让VLD捕捉任何内存泄漏,无论我如何尝试。你知道为什么吗

这里也是输出的一个片段:

Visual Leak Detector Version 2.4RC2 installed. 
The thread 0x5748 has exited with code 0 (0x0).
The thread 0x2c70 has exited with code 0 (0x0).
The thread 0x3c98 has exited with code 0 (0x0).
No memory leaks detected.
Visual Leak Detector is now exiting.
The program '[24988] ConsoleApplication2.exe' has exited with code 0 (0x0).

#包括
#包括
使用名称空间std;
班车{
公众:
Car(){}
汽车(字符串模型、整数年、字符串颜色){
本->型号=型号;本->颜色,本->年份=年份;
}
字符串getModel(){
返回此->模型;
}
void setModel(字符串m){
这个->模型=模型;
}
字符串getColor(){
返回此->颜色;
}
void setColor(字符串颜色){
这个->颜色=颜色;
}
空漆()
{
设置颜色(“白色”);
}
私人:
弦模型;
国际年;
字符串颜色;
};
int _tmain(int argc,_TCHAR*argv[]{
c车(“宝马”,2000年,“红色”);
c、 油漆();

cout它在visual studio 2013 ultimate下工作

您必须在控制台模式下执行程序(转到项目的调试目录)

在下面,您将看到结果的图片,但控制台显示了许多漏洞,我们无法在这里看到所有漏洞

我将include和lib路径添加到项目设置中

  • C:\ProgramFiles(x86)\VisualLeakDetector\include
  • C:\ProgramFiles(x86)\VisualLeakDetector\lib\win32
  • C:\ProgramFiles(x86)\VisualLeakDetector\lib\win64
  • 如您所见,有13个内存泄漏

    #include <vld.h>
    
    #include <iostream>
    using namespace std;
    
    class Car{
        public:
            Car() {}
    
            Car(string model,int year, string color) {
                this->model = model; this->color, this->year = year;
            }
    
            string getModel() {
                return this->model;
            }
    
            void setModel(string m) {
                this->model = model;
            }
    
            string getColor() {
                return this->color;
            }
    
            void setColor(string color) {
                this->color = color;
            }
    
            void paint()
            {
                setColor("white");
            }
    
        private:
            string model;
            int year;
            string color;
    };
    
    
    int _tmain(int argc, _TCHAR* argv[]){
        Car c("bmw", 2000, "red");
        c.paint();
        cout << c.getColor().c_str();
    
        for (int i = 0; i < 10; i++)
            int *ptr = new int(10);
    
        Car *c2 = new Car("benz", 2010, "yellow");
    
        return 0;
     }