Bonjour,
Je suis en train d'�crire une classe de gestion de grands entiers, et j'aimerais red�finir les op�rateurs de base.
Seulement voil�, j'ai une erreur de linkage que je n'arrive pas � r�soudre (ou pas comme je veux en tout cas).
voici le code de ma classe :
j'ai d�fini mon op�rateur + en dehors de ma classe mais dans un namespace.
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 #ifndef BIGINT_H #define BIGINT_H #include <iostream> #include <string> using namespace std; namespace RSAPTut { class BigInteger { private: int size; // le nombre de chiffres int sign; // -1 si <0, 0 sinon unsigned short * number; // chiffres du moins significatif au plus significatif public: // Constructeurs BigInteger(); BigInteger(BigInteger * big); // Getters inline int getSign() { return this->sign; } inline int getSize() { return this->size; } unsigned short * getNumber() { return this->number; } // Setters inline void setSign(int sign) { this->sign=sign; } inline void setSize(int size) { this->size=size; } inline void setNumber(unsigned short * number, int size) { this->size = size; this->number = new unsigned short[size]; // on alloue la mémoire pour number for (int i=0; i<size; i++) this->number[i] = number[i]; // on recopie la valeur dans number } // Utilitaires void print(); void stringToBigInteger(char * s); void setDigit(unsigned short d); }; // Méthodes primitives [...] // Opérations de base BigInteger add(BigInteger M, BigInteger N); // Addition [...] // Opérations modulaires [...] // Opérateurs BigInteger operator+(const BigInteger &m, const BigInteger &n) { BigInteger r = new BigInteger( add(m,n) ); return r; } }; #endif
En plus de ce code j'ai :
- l'impl�mentation dans un fichier s�par�, qui inclus ce .h et o� toutes les m�thodes sont impl�ment�es dans le namespace
- un fichier main pour tester
Si je compile tel quel, j'obtiens le message d'erreur :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11 Compiling... main.cpp BigInteger.cpp Linking... main.obj : error LNK2005: "class RSAPTut::BigInteger __cdecl RSAPTut::operator+(class RSAPTut::BigInteger const &,class RSAPTut::BigInteger const &)" (??HRSAPTut@@YA?AVBigInteger@0@ABV10@0@Z) already defined in BigInteger.obj main.obj : error LNK2005: "class RSAPTut::BigInteger __cdecl RSAPTut::operator+(class RSAPTut::BigInteger const &,class RSAPTut::BigInteger const &)" (??HRSAPTut@@YA?AVBigInteger@0@ABV10@0@Z) already defined in BigInteger.obj Debug/RSA.exe : fatal error LNK1169: one or more multiply defined symbols found Error executing link.exe. RSA.exe - 3 error(s), 0 warning(s)
J'arrive � faire fonctionner l'op�rateur en le d�finissant dans le fichier ou se trouve le main :
Voil� donc je ne sais pas comment r�soudre ce probl�me (je ne souhaite pas mettre tous les op�rateurs dans le main.cpp), donc si quelqu'un sait comment faire ?
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12 // Opérateurs RSAPTut::BigInteger operator+(const RSAPTut::BigInteger &m, const RSAPTut::BigInteger &n) { RSAPTut::BigInteger r = new RSAPTut::BigInteger( RSAPTut::add(m,n) ); return r; } int main() { [...] }
merci.
Partager