valgrind를 사용하여 다음 함수에서 크기가 잘못 읽었습니다. 나는 왜 그런지 잘 모르겠지만 아무도 나를 도울 수 있다면 크게 감사 할 것입니다! 내가 말할 수있는 것은 괜찮습니다.하지만 여전히 메모리 할당과 할당 해제를 처리 할 수있는 오류가 있습니다. 도와주세요!valgrind에서 크기가 잘못 읽고 쓰여졌습니다.
//alternate constructor that allows for setting of the inital value of the string
MyString::MyString(const char *message)
{
int counter(0);
while(message[counter] != '\0')
{
counter++;
}
Size = counter;
**String = new char [Size];**
for(int i=0; i < Size; i++)
String[i] = message[i];
}
istream& operator>>(istream& input, MyString& rhs)
{
char* t;
int size(256);
t = new char[size];
input.getline(t,size);
**rhs = MyString(t);**
delete [] t;
return input;
}
/*Assignment operator (=) which will copy the source string into the destination string. Note that size of the destination needs to be adjusted to be the same as the source.
*/
MyString& MyString::operator=(const MyString& rhs)
{
if(this != &rhs)
{
delete [] String;
**String = new char[rhs.Size+1];**
Size = rhs.Size;
for(int i = 0; i < Size; i++)
{
** String[i] = rhs.String[i];**
}
}
return *this;
}
제안 사항 ?? (모든 문제 줄에는 **이 있습니다.)
정확히 어느 라인에서? –
그 정보를 게시 했어야합니다. 특정 방법으로 강조 표시된 특정 줄을 사용하여 질문을 편집합니다. 죄송합니다! – user1363061