pointer initialization

hi,

i have some diffuculties in understanding a sample code:

#define MAX 32
#define MIN 1
#define NUMBER_OF_CARD MAX*MIN

typedef float BUFFER[NUMBER_OF_CARD];
typedef float *BUFFER_PTR;

BUFFER AO_BUFFER;
BUFFER_PTR ptrBuffer = AO_BUFFER;


ok, Does this code sample mean the line below:

float *ptrBuffer = float[32];

i think it doesn't mean. so can anyone explain me what does it mean?

Question 2: i have a class and there is a pointer as a private member.

class A {
public:
A();
virtual ~A();
private:
float *m_ptrValue[32];
};


how can i initialize m_ptrValue? i couldn't initialize it.
i wrote a function and i've tried to initialize it like below:

m_ptrValue[32] = new float[32];

but i had compile time errors. thanks for help.

To answer your first question, the code basically says this:

1
2
float AO_BUFFER[32];
float *ptrBuffer = AO_BUFFER;


ptrBuffer points to the first element in AO_BUFFER.

Secondly, m_ptrValue is going to be a 2D array. You need to allocate each pointer like this:

1
2
for (size_t i = 0; i < 32; ++i)
    m_ptrValue[i] = new float[32];


And then you need to free each one when you've finished with it.
Last edited on
thanks a lot :)
Topic archived. No new replies allowed.