IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

constructeur, destructeur ou conversion de type attendue. c'est quoi cette erreur?


Sujet :

C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Game Graphics Programmer
    Inscrit en
    Août 2006
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Game Graphics Programmer
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2006
    Messages : 408
    Par défaut constructeur, destructeur ou conversion de type attendue. c'est quoi cette erreur?
    Bonjour,
    dans le code ci-dessous, j'obtiens 2 fois la même erreur de compilation disant "error: expected constructor, destructor or type conversion before 'kazu'".
    Je n'arrive pas à m'expliquer cette erreur, ni de quoi elle résulte, ni comment la résoudre. J'espère qu'une âme éclairée et châritable arrive à me l'expliquer, voire à la corriger.

    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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
     
    #include <iostream>
     
    namespace kazu 
    {
    	//forward declarations
    	namespace base 
    	{
    		template<typename T, unsigned int L>
    		struct	vecN;
     
    		template<typename T, unsigned int L>
    		struct	vecD;
    	}
     
    	namespace math
    	{
    		template<
    		typename T,
    		unsigned int L,
    		typename V = kazu::base::vecD<T, L>
    		>
    		struct	vecmath;
    	}
     
     
    	//typedefs
    	template<typename T>
    	struct blast
    	{		
    		typedef base::vecD<T, 2> vec2;
    		typedef base::vecD<T, 3> vec3;
    		typedef base::vecD<T, 4> vec4;
     
     
    	};
    }
     
    namespace kazu
    {
    	namespace base 
    	{
    		template<typename T>
    		struct	vecD<T, 2> : kazu::math::vecmath<T, 2>
    		{
    			union
    			{
    				T	_v[2];
    				struct	{ T x, y;};
    				struct	{ T s, t;};
    				struct	{ T i, a;};
    			};
    			vecD(const T v[2]): x(v[0]), y(v[1]) {}
    			vecD(T x_ = (T)0, T y_ = (T)0): x(x_), y(y_)	{}
    			vecD(const vecD& ref): x(ref.x), y(ref.y) {}
    		};
     
    		template<typename T>
    		struct	vecD<T, 3> : kazu::math::vecmath<T, 3>
    		{
    			union
    			{
    				T	_v[3];
    				struct	{ T x, y, z;};
    				struct	{ T s, t, p;};
    				struct	{ T r, g, b;};
    			};
    			vecD(const T v[3]): x(v[0]), y(v[1]), z(v[2]) {}
    			vecD(T x_ = (T)0, T y_ = (T)0, T z_ = (T)0): x(x_), y(y_), z(z_)	{}
    			vecD(const vecD& ref): x(ref.x), y(ref.y), z(ref.z) {}			
    		};
     
    		template<typename T>
    		struct	vecD<T, 4> : kazu::math::vecmath<T, 4>
    		{
    			union
    			{
    				T	_v[4];
    				struct	{ T x, y, z, w;};
    				struct	{ T s, t, p, q;};
    				struct	{ T r, g, b, a;};
    			};
    			vecD(const T v[4]): x(v[0]), y(v[1]), z(v[2]), w(v[3]) {}
    			vecD(T x_ = (T)0, T y_ = (T)0, T z_ = (T)0, T w_ = (T)0): x(x_), y(y_), z(z_), w(w_)	{}
    			vecD(const vecD& ref): x(ref.x), y(ref.y), z(ref.z), w(ref.w) {}			
    		};
     
    		template<typename T, unsigned int L>
    		struct vecN : 
    			vecD<T, L>,
    		kazu::math::vecmath<T, L>
    		{			
    		};
     
    	}
     
    	namespace math
    	{
    		template<
    			typename T,
    			unsigned int L,
    			typename V
    		>
    		struct	vecmath
    		{
    			typedef	T	scalar_type;
    			typedef V	vector_type;
    			enum		{ vector_length = L };
     
    			static V cross(const V& rhv, const V& lhv);
     
    			static T dot(const V& rhv, const V& lhv);			
    			static V lerp(const V& rhv, const V& lhv, float t);
     
    		};		
    	}
    }
     
    using namespace kazu;
     
     
    template<typename T>
    kazu::math::vecmath<T, 2>::vector_type
    kazu::math::vecmath<T, 2>::cross( //erreur ici
    kazu::math::vecmath<T, 2>::vector_type& rhv,
    kazu::math::vecmath<T, 2>::vector_type& lhv)
    {
     
    	//impl
    	return kazu::math::vecmath<T, 2>::vector_type(rhv.x* lhv.y, rhv.y * lhv.x);
    }
     
     
    template<typename T>
    kazu::math::vecmath<T, 2>::scalar_type
    kazu::math::vecmath<T, 2>::dot( //erreur ici
    kazu::math::vecmath<T, 2>::vector_type& rhv,
    kazu::math::vecmath<T, 2>::vector_type& lhv)
    {
     
    	//impl
    	return kazu::math::vecmath<T, 2>::value_type(0);
    }
     
     
     
    int main (int argc, char * const argv[]) 
    {
    	//using kazu::blast<float>;
     
    	kazu::blast<float>::vec2 a2;
    	kazu::blast<float>::vec2 b2;
    	kazu::blast<float>::vec2 c2(kazu::blast<float>::vec2::cross(a2, b2));
    	float dot2 = kazu::blast<float>::vec2::dot(a2, c2);
     
    	kazu::blast<float>::vec3 a3;
    	kazu::blast<float>::vec3 b3;
    	kazu::blast<float>::vec3 c3(kazu::blast<float>::vec3::cross(a3, b3));
    	float dot3 = kazu::blast<float>::vec3::dot(a3, c3);
     
     
     
        // insert code here...
        std::cout << "Hello, World!\n" << dot2 << dot3;
        return 0;
    }
    Notez que je compile avec GCC 4.x de Xcode 3.1 sous MacOSX 10.5.6.
    A quoi cette erreur est-elle due?
    Comment la résoudre ou la contourner?

  2. #2
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    typename kazu::math::vecmath<T, 2>::vector_type
    ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    typename kazu::math::vecmath<T, 2>::scalar_type
    ...

  3. #3
    Expert confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2003
    Messages
    3 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 3 549
    Par défaut
    Il manque des typename dans plein d'endroits.
    C'est fou comment les gens peuvent avoir du mal avec cette règle toute simple...

  4. #4
    Membre émérite Avatar de HanLee
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    738
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Mai 2004
    Messages : 738
    Par défaut
    Une somme de règles simples ne fait pas un langage simple !

  5. #5
    Membre éclairé
    Homme Profil pro
    Game Graphics Programmer
    Inscrit en
    Août 2006
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Game Graphics Programmer
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2006
    Messages : 408
    Par défaut
    sachant que ce sont les 2 défintions de fonctions qui sont erronnées, quelle serait la facon correcte de les écrire?

    (Puis c'est quoi la règle toute simple derrière les typename?)

    J'ai essayé dans tous les sens, mais j'obtiens d'autres erreurs du coup, donc j'aimerais savoir quel est la facon correcte de faire ce que je tente ici.

  6. #6
    Expert confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2003
    Messages
    3 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 3 549
    Par défaut
    Si T est un type qui dépend d'un paramètre template, et que T::foo est un type et non une variable, il faut écrire typename T::foo.

Discussions similaires

  1. Réponses: 2
    Dernier message: 02/05/2011, 21h58
  2. Conversion de type
    Par poirier dans le forum ASP
    Réponses: 2
    Dernier message: 06/07/2004, 10h30
  3. [MYSQL] conversion de type sur import de script
    Par sebos63 dans le forum SQL Procédural
    Réponses: 2
    Dernier message: 27/08/2003, 10h00
  4. Réponses: 2
    Dernier message: 05/06/2002, 12h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo