class A { public: void eat(){ cout<<"A";} }; class B: virtual public A { public: void eat(){ cout<<"B";} }; class C: virtual public A { public: void eat(){ cout<<"C";} }; class D: public B,C { public: void eat(){ cout<<"D";} }; int main(){ A *a = new D(); a->eat(); } ダイヤモンドの問題を理解しています。上記のコードにはその問題はありません。 …
ELFハッシュアルゴリズムでチルド演算子が使用されているのを見てきましたが、その機能に興味があります。(コードはEternally Confusedからのものです。) unsigned elf_hash ( void *key, int len ) { unsigned char *p = key; unsigned h = 0, g; int i; for ( i = 0; i < len; i++ ) { h = ( h << 4 ) + p[i]; g = h & 0xf0000000L; if ( …
テンプレート関数と2つのクラスがあるとします class animal { } class person { } template<class T> void foo() { if (T is animal) { kill(); } } Tが動物かどうかの確認方法を教えてください。実行時にチェックするものは必要ありません。ありがとう
私はどのようにstd::unique_ptr機能するかを理解しようとし、そのためにこのドキュメントを見つけました。著者は次の例から始めます。 #include <utility> //declarations of unique_ptr using std::unique_ptr; // default construction unique_ptr<int> up; //creates an empty object // initialize with an argument unique_ptr<int> uptr (new int(3)); double *pd= new double; unique_ptr<double> uptr2 (pd); // overloaded * and -> *uptr2 = 23.5; unique_ptr<std::string> ups (new std::string("hello")); int len=ups->size(); 私を混乱させているのは、この行にあることです unique_ptr<int> uptr …