Установка значений для динамического массива объектов оказалась хитрой.Я пытаюсь сделать это классическим способом с помощью методов.
void Function(CallsOfTheObject * r){
const char DELIM = '>' ;
ifstream file("file.txt");
string sTemp;
int ri = 1;
while(getline(file, sTemp)) {
if(!sTemp.empty() && sTemp[0]==DELIM){
Expand(r, ri);
r[ri].setName(sTemp.substr(1)); //The line resulting with error
и других используемых функций и методов:
void Expand(CallsOfTheObject *r, int ri){
CallsOfTheObject* newR = new CallsOfTheObject[ri];
for (int i = 0; i < ri; i++){
if(r[i].getName() != ""){
newR[i] = r[i];
}else{
newR[i] = CallsOfTheObject();
}
}
delete []r;
r = newR;
}
....
void setName (string a) { partsName = a; }
Я продолжаю получать эту ошибку:
System.Runtime.InteropServices.SEHException was unhandled
Message: External component has thrown an exception.
Я предполагаю, что я где-то не освободил память или сделал очень маленькую ошибку, такую как опечатка ...
РЕДАКТИРОВАТЬ: я добавил указательСимволом функции Expand, но единственное, что изменилось, была ошибка:
System.AccessViolationException was unhandled
Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Похоже, я не очистил часть памяти или не пытался перезаписать существующую память неподходящим образом.По крайней мере, код, который я разместил, выглядит чистым ... для меня.
РЕДАКТИРОВАТЬ 2: Я смотрю на мой стек вызовов, но он не говорит мне много.Не могли бы вы exolain tome, что это значит?
S2_L2.exe!std::char_traits<char>::copy(char* _First1, char* _First2, unsigned int _Count) Line 497 C++
S2_L2.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(std::basic_string<char,std::char_traits<char>,std::allocator<char> >& _Right, unsigned int _Roff, unsigned int _Count) Line 904 + 0x28 bytes C++
S2_L2.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(std::basic_string<char,std::char_traits<char>,std::allocator<char> >& _Right) Line 888 + 0x13 bytes C++
S2_L2.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::operator=(std::basic_string<char,std::char_traits<char>,std::allocator<char> >& _Right) Line 764 + 0xc bytes C++
S2_L2.exe!Recipe::setName(std::basic_string<char,std::char_traits<char>,std::allocator<char> >* a) Line 22 + 0xb bytes C++
S2_L2.exe!InputR(Recipe&& r) Line 146 C++
> S2_L2.exe!main(array<System::String^> ^ args) Line 120 C++