-5
assocTab::swap()
메서드에서 내 개체의 isCaseSensitive
값을 변경할 수없는 이유는 무엇입니까? isCaseSensitive
필드는 assocTab()
생성자 내부에서 초기화됩니다. isCaseSensitive
가 속한클래스 필드의 값 변경 C++ - '조건부 점프 또는 이동이 단위 화 된 값에 따라 달라짐'
==13666== Conditional jump or move depends on uninitialised value(s)
==13666== at 0x401341: assocTab::setCaseSensitivity(bool) (assoctable.cpp:117)
==13666== by 0x401157: assocTab::swap(assocTab&) (assoctable.cpp:68)
==13666== by 0x4011C3: assocTab::operator=(assocTab const&) (assoctable.cpp:77)
==13666== by 0x4015FE: main (main.cpp:21)
==13666==
내 방법 simplifed 클래스 : Valgrind의 출력은
class assocTab{
private:
struct node{
node* next;
char* key;
int val;
};
node* head;
bool isCaseSensitive;
void clear();
void swap(assocTab& l);
public:
void setCaseSensitivity(bool);
bool getCaseSensitivity() const;
};
assocTab::assocTab(){
head = NULL;
setCaseSensitivity(true);
}
assocTab::assocTab(const assocTab& l){
node *src, **dst;
head = NULL;
src = l.head;
dst = &head;
try{
while(src){
*dst = new node (*src);
src = src->next;
dst = &((*dst)->next);
}
}catch(...){
clear();
throw;
};
}
void assocTab::swap(assocTab& l){
bool swpCS = getCaseSensitivity();
bool swpCS2 = l.getCaseSensitivity();
l.setCaseSensitivity(swpCS);
setCaseSensitivity(swpCS2); //line 68
std::swap(l.head, head);
}
void assocTab::setCaseSensitivity(bool isCS){
if(isCS) //line 117
isCaseSensitive = true;
else
isCaseSensitive = false;
}
bool assocTab::getCaseSensitivity() const{
return isCaseSensitive;
}
assocTab& assocTab::operator= (const assocTab& l){
if (&l == this)
return *this;
assocTab t(l);
swap(t);
return *this;
}
'assocTab'의 생성자에서'isCaseSensitive'를 초기 값으로 설정하면 사라지나요? 다른 사람들이 문제를 재현 할 수 있도록 [최소한의 완전하고 검증 가능한 예] (http://stackoverflow.com/help/mcve)를 포함시켜야합니다. –
아니요, 그렇지 않습니다. – Topkek
valgrind 출력에 연산자 =()이 표시됩니다. 그게 당신이 쓴 것이에요? –