LINUX.ORG.RU

[C++] глюк g++?

 


0

0

Вот такой код выдаёт ошибку компиляции на
i586-alt-linux-g++ (GCC) 4.4.1 20090725 (ALT Linux 4.4.1-alt1)

#include <iostream>
using namespace std;

template<class T>
struct A
{
template<class T1>
void foo( T1 * ) { cout << "foo(T1 *)" << endl; }

template<>
void foo<T>( T * ) { cout << "foo(T *)" << endl; }
};


int main()
{
A<int> a;
int q;
char c;

a.foo( &q );
a.foo( &c );

return 0;
}

$ g++ opyt.cpp
opyt.cpp:19: error: explicit specialization in non-namespace scope ‘struct A<T>’
opyt.cpp:20: error: template-id ‘foo<T>’ in declaration of primary template

icpc (ICC) 10.1 20080801
при этом компилирует и код работает как надо.

Это глюк g++? Его можно как-то обойти?


Что-то Comeau тоже ругается...

А как же мне шаблон специализировать?

yz
() автор топика
Ответ на: комментарий от Reset

Да, да. Я уже сообразил, спасибо.

yz
() автор топика

> Это глюк g++? 

Я бы сказал, что это глюк icpc.

[temp.expl.spec]
An explicit specialization shall be declared in the namespace of
which the template is a member, or, for member templates, in the
namespace of which the enclosing class or enclosing class
template is a member.  An explicit specialization of a member
function, member class or static data member of a class template
shall be declared in the namespace of which the class template
is a member.

Begemoth ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.