删除类指针

时间:2015-03-30 10:14:15

标签: c++ pointers visual-studio-2013

我有课程连接:

class Connection{
    public: Connection(string usr, string pwd);
            ~Connection();
    private:
        Engine *        pEngine;
        AdmCallbacks * pAdmCallbacks;
        Callbacks *      pCallbacks;
        char *           fake[11];
        int              iFlags;
        int              iCode;
};

~Connection()
{
        delete pEngine;
        delete pCallbacks;
        delete pAdmCallbacks;
}
在main.cpp中的

我做了这段代码:

#include <iostream>
#include "Connection.h"
using namespace std;
int main()
{
  Connection *connection = new Connection("test","test");
  if (logedin)
      //do something
  else delete connection;
  if (connection != NULL)
    cout << "WTF" << endl;
  return 0;  
}

输出:

WTF

为什么呢?我不明白为什么记忆没有处理..请帮帮我,谢谢!

0 个答案:

没有答案