access to dynamic allocated array

Hi,
I am having trouble with accessing dynamic arrays. I need to fill up two arrays in warpImage obj, then use them in another obj by calling getX(index) and getY(index) functions.

What I have is,
Header:
class warpImage {
public:
warpImage(int w, int h);
virtual ~warpImage();

void warp();
int getX(int index);
int getY(int index);

private:
int width, height;
int* X;
int* Y;
}

Source:
warpImage::warpImage(int w, int h)
{
width = w;
height = h;
X = new int[width*height];
Y = new int[width*height];
//have access to X and Y arrays here
}
warpImage::~warpImage()
{
delete [] X;
X = NULL;
delete [] Y;
Y = NULL;
}

warpImage::warp()
{
X and Y arrays should be filled here,
but I cannot access their elements, i.g.
by doing
X[index] = some int;
Y[index] = some int;
debugger got stuck and could not go through.
}

When I called getX() and getY() from another obj, of course it did not work, as the filling up phase was in trouble.

Can someone please help?
Thank you,
Shanshan

I see no obvious flaws in your code. You haven't implemented getX() or getY() though?
They are just standard get functions.
int warpImage::getX(int index)
{
return X[index];
}

I really don't understand why I cannot access in warp() and further export the X , Y in another obj....... weird
Please clarify on what you mean by other object? One that has instantiated warpImage? or one that has inherited from it?
Zaita,
hope you are still up.
I have another class called confidence, which instantiates warpImage. It looks like this

class confidence {
public:
confidence(warpImage& w);
virtual ~confidence();

void computeConfidence();
float triangleArea(int x0, int y0, int x1, int y1, int x2, int y2);

private:
warpImage* wI;
};

confidence::confidence(warpImage& w)
{
wI = &w;
}

confidence::~confidence()
{
}

float confidence::triangleArea(int x0, int y0, int x1, int y1, int x2, int y2)
{
getX() and getY() from warpImage are called here
some calculation
}
void confidence::computeConfidence()
{
some calculation
}

Thank you,
Shanshan
Last edited on
try these:

class confidence
{
public:
confidence();
virtual ~confidence();

void computeConfidence();
float triangleArea(int x0, int y0, int x1, int y1, int x2, int y2);

private:
warpImage* wI;
};

confidence::confidence()
{
wl = new warpImage(value_w, value_h);
}

confidence::~confidence()
{}

float confidence::triangleArea(int x0, int y0, int x1, int y1, int x2, int y2)
{
int valueX = wl -> getX(int indexX);
int valueY = wl -> getY(int indexY);

// warning: x0,y0,x1,y1,x2,y2 never used

}
void confidence::computeConfidence()
{
some calculation
}

Topic archived. No new replies allowed.