#include /*! ** @struct DerivedFrom ** ** Check if Type inherits BaseType. ** Raise a compilation error if this ** constraints is not respected. */ template<typename Type, typename BaseType> struct DerivedFrom { typedef void(*Func)(Type*); static void constraints(Type* type) { BaseType* base = type; base = base; } DerivedFrom() { Func f = constraints; f = f; } }; class A { }; class B : public A { }; class C { }; template <typename T> class Container : private DerivedFrom<T, A> // Pas besoin de public, un private suffit // vu que tu n'as besoin de rien dans la classe DerivedFrom { }; int main() { Container ca; Container cb; //Container<C> cc; // Erreur de compilation. C n'hérite pas de A. return 0; }
... ce que doit contenir un *.hxx par rapport à un *.cpp.
Suite à votre réponse, j'aimerais savoir ce qu'il faut ou non mettre en inline
class Critere : public ZoneComposite<Zone> { public: Critere( std::string nom= "" ); virtual ~Critere(); };
Critere::Critere( string nom ) : ZoneComposite<Zone>(nom) { } Critere::~Critere() { }
template <typename T = ZoneAbstraite> class ZoneComposite : public ZoneAbstraite, private DerivedFrom<T, ZoneAbstraite> { public: ZoneComposite( std::string nom="" ); virtual ~ZoneComposite(); virtual bool hasPoint( int const& x, int const& y ) const; // le point appartient-t'il à l'une des zones virtual std::ostream& afficher( std::ostream& flux, unsigned int const& etage ) const; protected: std::vector<T*> m_zones; };
Critere.cpp|| undefined reference to `ZoneComposite<Zone>::~ZoneComposite()'| Critere.o||In function `Critere::Critere(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':| Critere.cpp|| undefined reference to `ZoneComposite<Zone>::ZoneComposite(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'| Critere.o||In function `Critere::~Critere()':| Critere.cpp|| undefined reference to `ZoneComposite<Zone>::~ZoneComposite()'| Critere.o:(.rodata._ZTV7Critere[vtable for Critere]+0x10)||undefined reference to `ZoneComposite<Zone>::hasPoint(int const&, int const&) const'| Critere.o:(.rodata._ZTV7Critere[vtable for Critere]+0x14)||undefined reference to `ZoneComposite<Zone>::afficher(std::basic_ostream<char, std::char_traits<char> >&, unsigned int const&) const'|
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include #include "ZoneComposite.hpp" /*****************/ /* Constructeurs */ /*****************/ template <typename T> ZoneComposite<T>::ZoneComposite( std::string nom ) : ZoneAbstraite(nom) { } template <typename T> ZoneComposite<T>::~ZoneComposite() { } template <typename T> bool ZoneComposite<T>::hasPoint( int const& x, int const& y ) const { for( unsigned int i(0) ; i != m_zones.size(); i++ ) if( m_zones[i]->hasPoint(x,y) ) return true; return false; } template <typename T> std::ostream& ZoneComposite<T>::afficher( std::ostream& flux, unsigned int const& etage ) const { for( unsigned int i(0) ; i!=etage ; i++ ) flux << "\t"; flux << "[Zone Composite `" << getNom() << "` :"; for( unsigned int i(0) ; i!=m_zones.size() ; i++ ) { flux << "\n"; m_zones[i]->afficher( flux, etage+1 ); } flux << "\n]"; return flux; }