#include<iostream>
using namespace std;
class aClass
{
public:
char *message;
aClass(const char *message);
~aClass(){delete[] message;}
};
aClass::aClass(const char* newmessage)
{
message = new char[strlen(newmessage) +1];
strcpy(message,newmessage);
}
const ostream& operator<<(const ostream& o, const aClass &a)
{
o << a.message;
return o;
}
int main()
{
aClass b("Hello");
cout << b;
}
위의 코드가 무한 루프를 만드는 이유는 누구에게 설명 할 수 있습니까?오버로드시 오버플로 스택 오버플로 << 연산자
왜 단지'표준 : string'를 사용하지 :
는다음과 같이 작성해야 하는가? –
[3 가지 규칙] (http://en.wikipedia.org/wiki/Rule_of_three_%28C%2B%2B_programming%29)을 위반하고 있다는 점에 유의하십시오. 네가 수업을 복사하면 붐. 당신은 복사 생성자와 대입 연산자가 필요합니다. [copy-and-swap idiom] (http://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom)을 사용하십시오. 단지'std :: vector'또는'std :: string'을 사용해야합니다. –
GManNickG