Bonjour tout le monde,
j'ai une classe template my_int qui comme son nom ne l'indique pas peut etre instancier my_int<double> ou my_int<float>,
je voudrais faire un constructeur du type, a partir d'un my_int<double> me construit un my_int<float> mais je n'arrive pas à trouver la bonne syntaxe.
Voici mon fichier .h :
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 template<typename T> class my_int { public : my_int(const T value_); template<typename U> my_int(const U value_); template<typename U> my_int(const my_int<U> other_int); void add(const my_int<T> other_int); void multi(const my_double<T> d); T get(); void operator= (const my_double<T> d); private : T value; static const char * class_name; static const char * class_name1; //friend void my_double<T>::add(const my_int<T> other_int); friend void mult<>(my_double<T> &,const my_int<T> &,const my_double<T>&); }; #include "my_int.hpp"
et voici mon fichier hpp :
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 #include "my_double.h" template<typename U> class my_int; template<typename T> const char * my_int<T>::class_name = "faust_mat<T>::"; template<typename T> const char * my_int<T>::class_name1 = "faust_mat1<T>::"; template<typename T> my_int<T>::my_int(const T value_) : value(value_){} template<typename T> void my_int<T>::add(const my_int<T> other_int) { value += other_int.value; } template<typename T> T my_int<T>::get() { return value; } template<typename U> template<typename T> my_int<T>::my_int(const my_int<U> other_int) : value((U) value_){}; template<typename U> template<typename T> my_int<T>::my_int(const U value_) : value((T) value_){} template<typename T> void my_int<T>::multi(const my_double<T> d) { value *= d.value; } template<typename T> void my_int<T>::operator= (const my_double<T> d) { value = d.value; }
Merci d'avance
Partager