C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[g++] Spécialisation de template et erreurau link

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Vincent Richard
Guest





PostPosted: Mon Jan 03, 2005 7:57 pm    Post subject: [g++] Spécialisation de template et erreurau link Reply with quote



Bonsoir,

J'ai un petit problème pour compiler et linker le code suivant avec
la version 3.2 de GNU g++. Cela fonctionne sans problème avec les
versions suivantes (3.3 et 3.4) :

a.hpp (déclarations)
=====

template <typename TYPE>
struct A
{
void f() { /* ... */ }

TYPE v;
};

template <> void A <int>::f();

a1.cpp (définition de f() pour le type 'int')
======

#include "a.hpp"

template <> void A <int>::f()
{
// ...
}

a2.cpp (main)
======

#include "a.hpp"

int main()
{
A <int> a;
a.f();
}

Je compile avec la commande suivante :

$ g++ -o prog a1.cpp a2.cpp

L'erreur obtenue est la suivante (au link) :

/tmp/ccFY1RVe.o(.text+0x18): In function `main':
: undefined reference to `A<int>::f()'
collect2: ld returned 1 exit status

Est-ce un bug ? (apparement oui, car ça fonctionne dans les versions
suivantes) Y'a-t-il une astuce pour contourner ça, autre que de
définir la fonction dans le .hpp (en inline) ?

Merci d'avance pour vos réponses.

Vincent
Back to top
Pierre Lairez
Guest





PostPosted: Tue Jan 04, 2005 5:48 pm    Post subject: Re: [g++] Spécialisation de template et erreur au link Reply with quote




La syntaxe n'est pas

template <> void A <int>::f();

mais

template void A <int>::f();



Cependant, ton problème m'étonne, puisque A <int>::f() est déjà déclaré
explicitement, il ne devrait pas y avoir besoin du prototype...



Le Mon, 3 Jan 2005 20:57:29 +0100, Vincent Richard
<chere-loque (AT) plop (DOT) wanadoo.fr.invalid> a écrit:

Quote:
Bonsoir,

J'ai un petit problème pour compiler et linker le code suivant avec
la version 3.2 de GNU g++. Cela fonctionne sans problème avec les
versions suivantes (3.3 et 3.4) :

a.hpp (déclarations)
=====

template <typename TYPE
struct A
{
void f() { /* ... */ }

TYPE v;
};

template <> void A <int>::f();

a1.cpp (définition de f() pour le type 'int')
======

#include "a.hpp"

template <> void A <int>::f()
{
// ...
}

a2.cpp (main)
======

#include "a.hpp"

int main()
{
A <int> a;
a.f();
}

Je compile avec la commande suivante :

$ g++ -o prog a1.cpp a2.cpp

L'erreur obtenue est la suivante (au link) :

/tmp/ccFY1RVe.o(.text+0x18): In function `main':
: undefined reference to `A<int>::f()'
collect2: ld returned 1 exit status

Est-ce un bug ? (apparement oui, car ça fonctionne dans les versions
suivantes) Y'a-t-il une astuce pour contourner ça, autre que de
définir la fonction dans le .hpp (en inline) ?

Merci d'avance pour vos réponses.

Vincent


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.