uint64_tのtypedef以外の "set_type"という名前のデータ構造体に設定されたビット数に基づいてセカンダリソートを実行しようとしています。何がうまくいかないでしょうか?とにかく、文return(n1> n2)を削除すると、コードは完全に実行されます。しかし、SETにはノードをdouble値の昇順に、SET_TYPEで設定したビット数の降順に格納したい。セグメンテーションフォールト:セカンダリソートSET C++で11
struct setNode {
std::pair<double,set_type> data;
};
unsigned int bitCount (set_type value) {
unsigned int count = 0;
while (value > 0) { // until all bits are zero
if ((value & 1) == 1) // check lower bit
count++;
value >>= 1; // shift bits, removing lower bit
}
return count;
}
struct CompClass {
bool operator() (const setNode& lhs, const setNode& rhs) const
{
if (lhs.data.first == rhs.data.first) {
int n1 = bitCount(lhs.data.second);
int n2 = bitCount(rhs.data.second);
return n1 > n2;**//Statement causing error**
}
return lhs.data<rhs.data;
}
};
[mcve]を表示してください。 –