probleme de compilation separée : error LNK2005
Bonjour a tous,
Je n'en suis pas a ma premiere erreur de linkage, en cherchant sur internet j'ai trouvé que ce problème était très récurrent, mais pas vraiment de solution permettant de comprendre comment le compilateur fonctionne...:cry: et ainsi éviter les erreurs. En ce qui concerne mon problème actuel voila l'organisation de mes fichiers :
main.cpp :
Code:
1 2 3 4
| #include "GlobalFunctions.h"
#include "Visualisation.h"
#include "Exception.h"
#include <exception> |
Visualisation.h :
Code:
1 2
| #include <vector>
#include "Sprite.h" |
Visualisation.cpp :
Code:
1 2
| #include "Visualisation.h"
#include "Exception.h" |
Sprite.h :
Code:
1 2
| #include <iostream>
#include "Structure.h" |
et enfin Sprite.cpp :
Code:
1 2
| #include "Sprite.h"
#include "Exception.h" |
....jusque la aucun problème de compilation avec des headers ressemblant à :
Code:
1 2 3
| #if !defined(MY_VISUALISATOR_H)
#define MY_VISUALISATOR_H
#pragma once |
Maintenant en regardant de plus près ma classe Sprite une erreur apparait si je ne définit pas une spécialisation template directement au sein de ma classe voila un exemple que le compilateur accepte :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| class CSprite
{
.........
//fonction template :
template < bool ALPHA >
void drawSprite(BYTE * screen, const int & screenWidth, const int & screenHeight, const int & posX, const int & posY) const;
//specialisation
template <>
void drawSprite<false>(BYTE * screen, const int & screenWidth, const int & screenHeight, const int & posX, const int & posY) const;
};
template < bool ALPHA >
void CSprite::drawSprite(BYTE * screen, const int & screenWidth, const int & screenHeight, const int & posX, const int & posY) const
{
....
}
template < >
void CSprite::drawSprite<false>(BYTE * screen, const int & screenWidth, const int & screenHeight, const int & posX, const int & posY) const
{
....
} |
Si la fonction spécialisée est déclarée "en dehors" de ma fonction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| class CSprite
{
.........
//fonction template :
template < bool ALPHA >
void drawSprite(BYTE * screen, const int & screenWidth, const int & screenHeight, const int & posX, const int & posY) const;
}
template < bool ALPHA >
void CSprite::drawSprite(BYTE * screen, const int & screenWidth, const int & screenHeight, const int & posX, const int & posY) const
{....}
template < >
void CSprite::drawSprite<false>(BYTE * screen, const int & screenWidth, const int & screenHeight, const int & posX, const int & posY) const
{....} |
Alors mon compilateur n'accepte plus et me sort trois erreurs de linkage comme je les aimes:aie: :
Code:
1 2 3
| Sprite.obj : error LNK2005: "public: void __thiscall vis::CSprite::drawSprite<0>(unsigned char *,int const &,int const &,int const &,int const &)const " (??$drawSprite@$0A@@CSprite@vis@@QBEXPAEABH111@Z) déjà défini(e) dans main.obj
Visualisation.obj : error LNK2005: "public: void __thiscall vis::CSprite::drawSprite<0>(unsigned char *,int const &,int const &,int const &,int const &)const " (??$drawSprite@$0A@@CSprite@vis@@QBEXPAEABH111@Z) déjà défini(e) dans main.obj
D:\Mes documents\Visual Studio 2005\Projects\ProjectHAPI\Release\ProjectHAPI.exe : fatal error LNK1169: un ou plusieurs symboles définis à différentes reprises ont été rencontrés |
Quelqu'un aurait-il des informations qui pourrait m'aider a mieux comprendre comment eviter ces erreurs ? :roll:
Merci d'avance :king:
A bientot