Hello,
I have a class with some member fields that are pointers. I'm trying to set the pointer member fields with mutators (setters) but I'm getting memory access errors when I try to do this. This is how it's looking at the moment.
Class header containing member fields
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// include headers
class Model
{
public:
// Constructors and other Methods
// Mutators
void SetTexture(const BYTE *texture);
void SetPalette(const Gdiplus::Color *palette);
private:
BYTE* _texture;
Gdiplus::Color* _palette;
}
And here's the implementation of the mutator's in the model.cpp file
The mutator's take a pointer as a parameter as you can see except when they are called I'm getting this memory access violation. I'm pretty sure the mutator's are wrong, how should I be doing this?
They're definitely not uninitialized, I did actually noticed I'd set them to NULL rather than what cdlang said to change them to in the constructor, but that was giving me the error whereas I'm not getting the error when I initialize them with the new keyword and var type.
I also forgot to delete them in the destructor but that wasn't related to the error I was getting. Strangely the guide I'm following does tell me to initialize them to NULL.