1    //
2    // Week 2, Example #1
3    //
4    // Provides a simple class that does not
5    // implement a copy constructor.
6    //
7   
8    class foo
9    {
10    public:
11        foo () { myData = new int;}
12   
13        void setData (int x) { *myData = x;)
14        int getData () {return *myData;}
15   
16    private:
17        int *myData;
18    };
19   
20   
21    //
22    // Week 2, Example #2
23    //
24    // Example of when constructor and destructor
25    // is called for automatic variables
26    //
27   
28    void function ()
29    {
30        foo x;
31   
32        x.setData (5);
33    }
34   
35    //
36    // Week 2, Example #3
37    //
38    // Example of when constructor and destructor
39    // is called for dynamic variables
40    //
41   
42    void function ()
43    {
44        foo *x = new foo ();
45   
46        x->setData (5);
47   
48        delete x;
49    }
50   
51    //
52    // Week 2, Example #4
53    //
54    // Example of when constructor and destructor
55    // is called for dynamic variables. What's
56    // wrong with this example?
57    //
58   
59    void function ()
60    {
61        foo *x = new foo ();
62   
63        x->setData (5);
64    }
65