- MoreEffectiveC++/Exception
class AudioClip{
AudioClip(const string& audioDataFileName);
const string& audioClipFileName = "");
AudioClip *theAudioClip;
const string& audioClipFileName)
:theName(name), theAddress(address), theImage(0), theAudioClip(0)
if (audioClipFileName != "") { // 소리 정보를 생성한다.
theAudioCilp = new AudioClip( audioClipFileName);
delete theAudioClip;
생성자는 theImage와 theAudioClip를 null로 초기화 시킨다. C++상에서 null값이란 delete상에서의 안전을 보장한다. 하지만... 위의 코드중에 다음 코드에서 new로 생성할시에 예외가 발생된다면?
if (audioClipFileName != "") {
theAudioClip = new AudioClip(audioClipFileName);
이렇게 해도 여전히 문제는 남는다. 무엇이냐 하면, 만약 BookEntry의 생성자중에서 AudioClip 객체 생성중에 예외를 propagate하면 바로 위 코드중 pb 포인터에 null을 반환해 버린다. 반납된 이렇게 되면 이미 정상적으로 생성된 theImage를 지우지 못하는 사태가 발생해 버리는 것이다.
const string& audioClipFileName)
:theName(name), theAddress(address), theImage(0), theAudioClip(0)
if (audioClipFileName != "") {
theAudioCilp = new AudioClip( audioClipFileName);
delete theAudioClip;
const string& audioClipFileName)
:theName(name), theAddress(address), theImage(0), theAudioClip(0)
Found 1 matching page out of 7544 total pages
You can also click here to search title.