Pretty new to c++, i have a rather (i think) stupid question about a piece of code :
class DataStream
{
protected:
DataStream(void) { };
public:
DataStream(int Length);
~DataStream(void);
...
void* DataPtr;
int Length;
};
I do have a class similiar to this and i want to assign to DataPtr a pointer to some data allocated. When i do
DataStream::DataStream(int length)
{
char* arr = new char[length];
this->DataPtr = arr;
this->Length = length;
}
All i get is corrupting the class (the length variable assume strange values) and the dataptr is not the same as the arr pointer. Why is that? What am i missing?
EDIT for information :
Windows Platform, Visual Studio 2010, The implementation is just that (done in the constructor). The including class is a simple EMPTY class with only a constructor that calls in return the constructor of the DataStream class. The class name is ShaderFormat. In the main app the only lines are
ShaderFormat* sf = new ShaderFormat();
DataStream* ds = sf->Save();
I was not directly referencing DataStream in the main app, only the shaderformat classes. (that was the problem it seems) Why is that?