test

C

Public Domain

test

Download (right click, save as, rename as appropriate)

Embed

Tags:

test!!
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;

struct intHolder
{
     int *val;
};

class CIntHolder
{
public:
     CIntHolder() : theInt(0) {}
     ~CIntHolder() { theInt = 0; }

     void set(intHolder &ih) { ih.val = &theInt; }
     void load(intHolder &ih) { theInt = 1;  set(ih); }
     int getInt() { return theInt; }
private:
     int theInt;
};

void changeInt(intHolder *toChange)
{
     *(toChange->val) += 1;
}

int main()
{
     CIntHolder myCIntHolder;
     intHolder ih;
     myCIntHolder.set(ih);
     
     cout << "class internal: " << myCIntHolder.getInt() << endl;
     cout << "my copy:  " << *ih.val << endl;

     changeInt(&ih);

     cout << "class internal: " << myCIntHolder.getInt() << endl;
     cout << "my copy: " << *ih.val << endl;

     return 0;
}