I have same code:
.hpp file:
class CConsoleModel
{
char* ParametersBuffer;
...
public:
CConsoleModel() ; // - basic constructor;
~CConsoleModel() ; // -basic destructor
char *DeterminationParameter(std::string _command, int _parametersize);
...
};
.cpp file:
char *CConsoleModel::DeterminationParameter(std::string _command, int _parametersize)
{
ParametersBuffer = new char[_parametersize];
unsigned int HexValue;
_command = _command.substr(_command.length() - (_parametersize*2),(_parametersize*2));
//do conversion of the string to the required dimension (_parametrsize):
for (int i(0); i<_parametersize;i++)
{
std::stringstream CommandSteam;
CommandSteam<< std::hex <<_command[2*i];
CommandSteam<< std::hex <<_command[2*i +1];
CommandSteam >> std::hex >> HexValue;
ParametersBuffer[i] = static_cast<char> (HexValue);
}
return ParametersBuffer;
}
Program build, but crash when run.
If I change ParametersBuffer = new char[_parametersize]
to char* ParametersBuffer = new char[_parametersize]
everything works. How can I fix this problem?