0

In my main function I'm creating an array:

char arr[0x10000][9];

In another class B I would like to have a pointer to this array:

typedef char memory[0x10000][9];

class B{
   public:
      B(memory* mem);
   private:
   memory* _mem;
}

and the implementation

B::B(memory* mem){
   this->_mem = mem;
}

And the main function:

....
char arr[0x10000][9];   
arr[0][0] = 7; 
arr[0][1] = 7;
// and so on...
B* b = new B(&arr, true);
...

Unfortunately, I can only access _mem[0][0] correctly, if I access _mem[0][1], then I'm getting some random value, but not the one that I set in the main method.

netik
  • 1,736
  • 4
  • 22
  • 45
  • 1
    Who owns that pointer (= it is responsible to free that memory?) Are your objects copied (by value)? Is ownership transferred? – Adriano Repetti Dec 03 '15 at 09:15
  • 2
    [What is The Rule of Three?](http://stackoverflow.com/q/4172722/3309790) – songyuanyao Dec 03 '15 at 09:17
  • The main function "owns" the array, and I want to pass it by reference to my B class, which will only read from that array. I edited my question to make it more clearly. – netik Dec 03 '15 at 10:03

1 Answers1

1

Use (*_mem)[0][1]; to get the value. you have pointer to double dimensional array as data member

rahul.deshmukhpatil
  • 977
  • 1
  • 16
  • 31