|
-
Sep 18th, 2009, 11:59 PM
#1
[RESOLVED] Add an object of class to an array of objects
what am I doing wrong here? It is throwing runtime error on highlighted line
Code:
//My class
struct MYPOINT
{
int X;
int Y;
};
struct MYPALETTE
{
char R;
char G;
char B;
};
class MYPIXEL
{
private:
MYPOINT currentPoint;
MYPALETTE currentPalette;
public:
MYPOINT getCurrentPoint() { return currentPoint; };
MYPALETTE getCurrentPalette() { return currentPalette; };
void setCurrentPoint(MYPOINT point) { currentPoint = point; };
void setCurrentPalette(MYPALETTE pal) { currentPalette = pal; };
};
class MyImageClass
{
int Width;
int Height;
char ImagePath[_MAX_PATH];
MYPIXEL* pixels;
char* ImgData;
public:
MyImageClass() { };
~MyImageClass() { if(pixels) delete [] pixels; };
//void InitializePixelArray() { for(int count = 0; count < Width * Height; count++) pixels[count] = new MYPIXEL(); };
void setWidth(int w) { Width = w; };
void setHeight(int h) { Height = h; };
void setImagePath(char* path) { strcpy(ImagePath, path); };
void addPixel(MYPIXEL pxl, int location) { pixels[location] = pxl; };
int getWidth() { return Width; };
int getHeight() { return Height; };
MYPIXEL* getImagePixels() { return pixels; };
char* getImageData() { return ImgData; };
char* getImagePath() { return ImagePath; };
void ReadImagePixels();
void ReadImageData(MYPIXEL*);
}
//ReadImagePixels
void MyImageClass::ReadImagePixels()
{
FILE* _IN_FILE;
_IN_FILE = fopen(ImagePath, "rb");
int pixelCount = 0;
for(int x = 0; x < Width; x++)
{
for(int y = 0; y < Height; y++)
{
char c = fgetc(_IN_FILE);
MYPIXEL pxl;
struct MYPOINT point;
struct MYPALETTE pal;
point.X = x;
point.Y = y;
pal.R = 100;
pal.G = 100;
pal.B = 100;
pxl.setCurrentPoint(point);
pxl.setCurrentPalette(pal);
addPixel(pxl, pixelCount);
pixelCount++;
}
}
}
Basically, whenever I try to add the new MYPIXEL object to array pixels (in my image class), it gives me a runtime error and closes the program. Sorry, been long time I worked in C++, and never worked in VS 2008.
Please this is urgent.
Thank you.
BTW, if I remove this line or assignment, then this runs and gives me the output screen.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|