自分の型消去イテレータに取り組んでいる間、私は、コンパイラ(MSVC10)は、このコードのスタックオーバーフローで墜落した問題に走った:私はきた、明らかにコンパイラのスタックオーバーフロー
struct base {}; //In actual code, this is a template struct that holds data
template<class category, class valuetype>
struct any; //In actual code, this is abstract base struct
template<class basetype, class category, class valuetype>
struct from; //In actual code, this is function definitions of any
template<class valuetype>
struct any<void,valuetype>
{ void a() {} };
template<class category, class valuetype>
struct any
: public any<void,valuetype> //commenting this line makes it compile
{ void b() {} };
template<class basetype, class valuetype>
struct from<basetype,void,valuetype>
: public base //commenting out _either_ of these makes it compile
, public any<void,valuetype>
{ void c() {} };
int main() {
from<int, void, char> a;
a.a();
a.c();
any<int, char> b;
b.a();
b.b();
return 0;
}
バグが残っている場所をすべて削除しました。 (元のコードは780 +行でした)残りのテンプレートパラメータを削除すると、コードがコンパイルされます。
完全なエラーメッセージは次のとおりです。
main.cpp(23): fatal error C1063: compiler limit : compiler stack overflow
main.cpp(20) : see reference to class template instantiation 'from<basetype,void,valuetype>' being compiled
IDEOne compiles it fine。私は、MSVCが2フェーズルックアップを実装していると聞きましたが、これは関連性があると思われますが、from
がbase
から継承する行を削除すると、なぜコンパイルされるのか説明しません。 誰でもMSVC10がこれをコンパイルしない理由を教えてもらえますか?私は避けなければならないことは何をしたのですか?
、GCC 4.6は問題なくお使いのサンプルコードをコンパイルする(Linux/Debianの/シド/ AMD64上)。おそらく、あなたはGCCに切り替えることができます(例えばMinGWやCygwinのいくつかの亜種...)? –
私は実際にIDEOne経由でかなりの量のデバッグを行いましたが、私のコマンドライン-fuとlinuxは弱いので、Cygwinは威圧しています。私はそれでもおもちゃを始めます。 –
あなたは自分自身から継承するテンプレートクラスを持っていますか?または私はこれを間違って読んでいますか?それはAJG85 @最新のC++標準準拠... – AJG85