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 

template et héritage

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





PostPosted: Thu Aug 25, 2005 12:20 pm    Post subject: template et héritage Reply with quote



Bonjour

Je me remet au C++ apres un petit arret, et je me trouve confronté à un
probleme.
Je souhaite créer une classe template qui correspond uniquement à des
changement d'état à des positions données (concretement, en musique, on
peut avoir des changement de tempo, de signatures, de parties).

J'ai donc décider de créer une classe ainsi :

// trame.h

#include <map>
using namespace std;

typedef unsigned int t_pos;

template <class T>
class mapPosition : public map<t_pos,T>
{
public:
mapPosition(void);

public:
void clear(void);
const T& GetChangement(t_pos position) const;
bool SetChangement(t_pos position, const T& rcT);
};

Cette classe possede donc des objets rangés selon leur position, et
permet de récuperer une info à une position donnée, ou d'assigner un
nouveau changement d'état à une position.
J'ai quelques problemes de compilation :

// trame.cpp
#include "trame.h"

#include <iterator>
#include <iomanip>
#include <algorithm>
using namespace std;

template<class T>
mapPosition<T>::mapPosition(void)
{
clear();
}

template<class T>
void mapPosition<T>::clear(void)
{
map<t_pos,T>::clear();
insert( value_type(0, T()) );
}

//////////////////////////////////////////////////////////////////////
// GetChangement : retourne le changement a une position donnée
template<class T>
const T& mapPosition<T>::GetChangement(t_pos position) const
{
typename mapPosition<T>::const_iterator iter;
iter = find(position); // ERROR
if (iter == end()) // ERROR
{
iter = lower_bound(position);
--iter;
}
return (*iter).second;
}

//////////////////////////////////////////////////////////////////////
// SetChangement : assigne un changement a une position donnée
template<class T>
bool mapPosition<T>::SetChangement(t_pos position, const T& rcT)
{
...
}

Bon, en creusant un peu, j'ai supprimé ces erreurs en faisant préceder
chaque occurance à un appel d'une méthode le la classe parente map<> par
map<t_pos,T>:: afin de forcer l'appel de la méthode de la classe mere.

Mais ceci me fait apparaitre d'autres erreurs, notement lors de
l'instanciation :

mapPosition<Tempo> mapTempo;
mapTempo.clear(); // ERROR : il ne souhaite pas map<t_pos,T>::

Je ne comprends pas trop car il me semble que tout ceci fonctionnait
avec une version plus ancienne de gcc.

Je ne maitrise pas trop les templates, et surtout j'ai pas tout compris
aux 'typename'.

Cordialement
--
Jérémie
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.