The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

форумы  помощь  поиск  регистрация  майллист  ВХОД  слежка  RSS
"проблема компиляции на разных версиях gcc"
Вариант для распечатки  
Пред. тема | След. тема 
Форумы Программирование под UNIX (Public)
Изначальное сообщение [Проследить за развитием треда]

"проблема компиляции на разных версиях gcc"  
Сообщение от Vital email(??) on 03-Июн-06, 12:54 
вот минимальный проблемный код

1:
2:  template <class type>
3:  class c1 {
4:  public:
5:
6:          class c2 {
7:          public:
8:  
9:                  int a;
10:                 int b;
11:                 c2 ( int a, int b ) : a (a), b (b) {}
12:         };
13:
14:         c2      add     ( int, int );
15:
16:         type    d;
17: };
18:
19: template <class type>
20: c1<type>::c2
21: c1<type>::add ( int a, int b ) {
22:         return c2 (a,b);
23: }
24:
25: int main () {
26:         c1<int> A;
27: }
28:

вот как реагируют разные компиляторы на этот код
1:
%> gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.2 [FreeBSD] 20040728
%> g++ test.cpp
test.cpp:21: error: expected constructor, destructor, or type conversion before "c1"
test.cpp:21: error: expected `;' before "c1"
%>

2:
%> gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-53)
%> g++ test.cpp
test.cpp:21: warning: `typename c1<type>::c2' is implicitly a typename
test.cpp:21: warning: implicit typename is deprecated, please see the
   documentation for details
%>

3:
%> gcc -v
Using builtin specs.
gcc version 2.95.4 20020320 [FreeBSD]
%> g++ test.cpp
%>
никаких ошибок и предупреждений

как заставить это код компилироваться под gcc 3.4.2?

Правка | Высказать мнение | Ответить | Cообщить модератору | Наверх

 Оглавление

Сообщения по теме [Сортировка по времени, UBB]


1. "проблема компиляции на разных версиях gcc"  
Сообщение от Асен Тотин email on 03-Июн-06, 20:12 
Привет,

Как и говорит ва 3.2, вы имплицитно задаете имя класся. Раньше было можно, теперь gcc стал более требователен и ждет от вас описания что именно вы декларируете - класс, переменную и т.д. Немножко доументации:

The problem here is that when a compiler encounters something like classname::something, it has to decide whether this is a member variable, member function, or name of a type declared inside the class (e.g. a typedef or nested class). Often, compilers assume it is a type name - which would be correct in this case. However more recent compilers demand that you resolve this ambiguity. To get this warning to go away the type names must be explicitly identified as such:

        template <class Iter>
        inline
        typename iterator_traits<Iter>::value_type
        sum (Iter first, Iter last, typename iterator_traits<Iter>::value_type init)
        {
           ...
        }

WWell,

Правка | Высказать мнение | Ответить | Cообщить модератору | Наверх

2. "проблема компиляции на разных версиях gcc"  
Сообщение от Vital (??) on 05-Июн-06, 02:07 
большое спасибо))
Правка | Высказать мнение | Ответить | Cообщить модератору | Наверх

Архив | Удалить

Индекс форумов | Темы | Пред. тема | След. тема
Оцените тред (1=ужас, 5=супер)? [ 1 | 2 | 3 | 4 | 5 ] [Рекомендовать для помещения в FAQ]




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2025 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру