ふらっとC♯, C#(初心者用) Part11
■ このスレッドは過去ログ倉庫に格納されています
0054デフォルトの名無しさん
2006/12/18(月) 21:39:54Cでもコンパイル時の最適化で(A&B) と (A&B) != 0の違いはなくなるので後者で書くことも多いよ。
あえてやるなら >>47のいってる方法だが、激しくめんどくさい。
struct boolbits {
public boolbits(int i) { bits = i; }
public int bits;
public static bool operator true(boolbits b) { return b.bits != 0; }
public static bool operator false(boolbits b) { return b.bits == 0; }
public static boolbits operator&(boolbits b1, boolbits b2) { b1.bits &= b2.bits; return b1;}
public static boolbits operator|(boolbits b1, boolbits b2) { b1.bits |= b2.bits; return b1;}
public static boolbits operator~(boolbits b) { b.bits = ~(b.bits); return b; }
// 他にもキャスト演算子とかetc実装汁
}
■ このスレッドは過去ログ倉庫に格納されています