I cannot understand why my homework ask :(

This is my second homework but is too hard to me, a lot of things i cannot understand. At Least help me finish two part, thanks a lots :D
#include <iostream>
using namespace std;

class int_array_cell
{
private:
int _counter;
int * _memory;
};

class counter_ptr
{
private:
char * _name;
int_array_cell * _cell_ptr;
};

void main()
{

// PART 1

counter_ptr b("b", new int[10]); <- one b here
// stdout output: int_array_cell is allocated
// stdout output: counter_ptr b is assigned to an int_array_cell: counter 1

{

b = new int[100]; why got another b ??
// stdout output: int_array_cell counter 0: deleted
// stdout output: int_array_cell is allocated
// stdout output: counter_ptr b is assigned to an int_array_cell: counter 1

counter_ptr a("a"); two a?
// stdout output: counter_ptr a is not assigned to an int_array_cell

a = b;
// stdout output: int_array_cell counter is increased: counter 2 <- cannot get it
// stdout output: counter_ptr a is assigned to an int_array_cell: counter 2

}
// a leaves it scope:
// stdout output: counter_ptr a is deleted
// stdout output: int_array_cell counter is decreased: counter 1

// PART 2

for(int i=0; i<10; i++)
b[i] = i;

for(int i=0; i<10; i++)
cout << b[i] << ' ';
cout << endl;
// stdout output: 0 1 2 3 4 5 6 7 8 9

counter_ptr c("c");
// stdout output: counter_ptr c is not assigned to an int_array_cell

c = b;
// stdout output: int_array_cell counter is increased: counter 2
// stdout output: counter_ptr c is assigned to an int_array_cell: counter 2

b.release();
// stdout output: int_array_cell counter is decreased: counter 1
// stdout output: counter_ptr b is not assigned to an int_array_cell

}

// stdout output: counter_ptr c is deleted
// stdout output: int_array_cell counter 0: deleted
// stdout output: counter_ptr b is deleted

/*
PART 3
1) using template rewrite class counter_ptr
2) repeat PART 1 2 test
what exactly is the assignment wanting you to do, and what exactly do you not understand?
all I see are requests for output statements (???) which does not seem correct.
i just copy the home work and paste here, i don change anything.
I can't make any sense of what they want you to do. You don't have any instructions?
You may need to ask your professor.

also, among other issues, void main is not legal. Compilers will take it, if set to low error thresholds, but main is supposed to be int.
Last edited on
ok, got it
Topic archived. No new replies allowed.