美文网首页
43 - Deconstructors

43 - Deconstructors

作者: 社交帐号直接注册 | 来源:发表于2018-01-02 13:52 被阅读0次
  1. main.cpp
#include <iostream>
#include "Sally.h"
using namespace std;

int main()
{
Sally sallyObject;
//first
sallyObject.printCrap();
//third
Sally *sallyPointer = &sallyObject;
sallyPointer->printCrap();
//third
Sally so;
//first
cout << "fourth" << endl;
//fourth
//second
return 0;
}
  1. Sally.h
#ifndef SALLY_H
#define SALLY_H

class Sally
{
public:
    Sally();
    ~Sally();
    void printCrap();
protected:
private:
};

#endif // SALLY_H
  1. Sally.cpp
#include "Sally.h"
#include <iostream>
using namespace std;

Sally::~Sally()
{
    cout << "second" << endl;
}

void Sally::printCrap()
{
    cout << "third" << endl;
}


Sally::Sally()
{
    cout << "first" << endl;
}

相关文章

网友评论

      本文标题:43 - Deconstructors

      本文链接:https://www.haomeiwen.com/subject/lidfnxtx.html