43 - Deconstructors

  1. main.cpp
#include 
#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 
using namespace std;

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

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


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

你可能感兴趣的:(43 - Deconstructors)