私は同じコードを持っています:
.hpp ファイル:
class CConsoleModel
{
char* ParametersBuffer;
...
public:
CConsoleModel() ; // - basic constructor;
~CConsoleModel() ; // -basic destructor
char *DeterminationParameter(std::string _command, int _parametersize);
...
};
.cpp ファイル:
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;
}
プログラムはビルドされますが、実行するとクラッシュします。
私が変わればParametersBuffer = new char[_parametersize]
にchar* ParametersBuffer = new char[_parametersize]
すべてが機能します。この問題を解決するにはどうすればよいですか?