Препроцессор в VC++
От: CrystaX Россия https://crystax.me/
Дата: 19.10.05 19:39
Оценка:
Перейду сразу к вопросу:

// incl1.hpp
typename T1, typename T2, typename T3

// incl2.hpp
struct a1 {};
struct a2 {};
struct a3 {};

// test.cpp
template <
#include "incl1.hpp" // Тут VC 7.1 и 8.0 не хотят компилить
>
struct foo {};

#include "incl2.hpp" // Тут все ок

int main()
{
    foo<a1, a2, a3> bar;
    
    return 0;
}


Пытаемся скомпилировать:
D:\Temp>cl /EHsc /I. test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

test.cpp
test.cpp(3) : error C2501: 'T3' : missing storage-class or type specifiers
test.cpp(10) : error C2975: 'foo' : invalid template argument for 'T3', compile-time evaluatable constant expression expected
        test.cpp(4) : see declaration of 'foo'
test.cpp(10) : error C2955: 'foo' : use of class template requires template argument list
        tst.cpp(4) : see declaration of 'foo'
test.cpp(10) : error C2133: 'bar' : unknown size
test.cpp(10) : error C2512: 'foo' : no appropriate default constructor available
test.cpp(10) : error C2262: 'bar' : cannot be destroyed


D:\Temp>cl /EHsc /I. test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50215.44 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp
test.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
test.cpp(10) : error C2975: 'foo' : invalid template argument for 'T3', expected compile-time constant expression
        test.cpp(4) : see declaration of 'foo'
test.cpp(10) : error C2133: 'bar' : unknown size
test.cpp(10) : error C2512: 'foo' : no appropriate default constructor available


GCC 3.4.2 (MinGW) и Intel (8.1, 9.0) компилируют без проблем.
Кто виноват, в общем-то понятно, но что делать?
... << RSDN@Home 1.1.4 stable rev. 510>>
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.