Работая над своим собственным итератором стирания типа, я столкнулся с проблемой, когда компилятор (MSVC10) вылетал из-за переполнения стека в этом коде:
struct base {}; //In actual code, this is a template struct that holds data
template
struct any; //In actual code, this is abstract base struct
template
struct from; //In actual code, this is function definitions of any
template
struct any
{ void a() {} };
template
struct any
: public any //commenting this line makes it compile
{ void b() {} };
template
struct from
: public base //commenting out _either_ of these makes it compile
, public any
{ void c() {} };
int main() {
from a;
a.a();
a.c();
any 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' being compiled
IDEOne отлично компилирует . Я слышал, что MSVC неправильно реализовал двухфазный поиск, что кажется актуальным, но не объясняет, почему он компилируется, когда я удаляю строку, которая делает из
наследованием от базы
. Кто-нибудь может научить меня, почему MSVC10 не компилирует это? Чего я сделал, чего следует избегать?