동적 메모리 할당 질문이요!!
쌍둥이자리
2023.04.01
String String::substr (size_t pos, size_t len ) const
{
String *tmp = new String;
for(size_t j=0, i=pos; ipos+len; i++,j++ )
{
tmp[j] = this- itsString[i];
}
*this = *tmp;
delete tmp;
return *this;
} 제가 tmp라는 동적메모리를 할당하고 for문을 실행한 후에 그 결과인 tmp의 포인터를 this에 넣고 tmp를 해제하고 this를 반환했는데....이렇게 하면 안되나요...? 자꾸 오류가 뜨는데 어떻게 수정해야 하나요?