colors::colors()
{
ColorData Propiedades[max_colors] =// this is local (constructor) variable, not class instance Propiedades.
{
{ 0, "black", 0, 0, 0},
{ 1, "white",255,255,255},
{ 2, "darkGray",128,128,128},
{ 3, "gray",160,160,164},
...
};
p=&Propiedades[0]; // p now points to local (ctor) variable which will be diallocated
//right now.
}
int colors::getRed(int num)
{
ColorData *q;
q=p; // p points to deallocated memory.
for (int i=0;i<=max_colors;i++){// bad, must be "i < max_colors" or even "i < colors::max_colors".
if (num==q->num) return q->R;
q++;
}
return 0;
}
Bookmarks