So i would like to have a constant pointer as field in my class becouse it must ALWAYS point to first cell. Problem is I can't do it since I am allocating memory in constructor. I was thinking about inicialization list but memory allocated is dependent on size of arguments; in C# I'd use ,,readonly''. No idea how to do it in C++
class Package{
private: char *const pack ; // <-- here
public: Package(PackInfo pckInfo, Data file) ;
public: ~Package();
};
Package::Package(PackInfo pckInfo, Data data){
this->headerSize = sizeof(pckInfo);
this->sizeOfData = data.GetDataSize();
//alocate memory
this->pack = new char[this->sizeOfData + this->headerSize](); //<- can not be done
//pointer on the begining of allocated array
PackInfo *temp = (PackInfo*) this->pack;
//putting header information in the begining of the array // moving pointer at cell just after header information
*temp = pckInfo; temp++;
char *packPointer = (char*)temp;
//getting data from file direclty into the array
data.GetCurrentBytes(packPointer);
}