ho ritrovato l'esempio , shodan pero ' è cosi :
.inl
codice://---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> Tuple<DIMENSION,TYPE>::Tuple () { // Uninitialized for native data. Initialized for class data as long as // TYPE's default constructor initializes its own data. } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> Tuple<DIMENSION,TYPE>::Tuple (const Tuple& tuple) { for (int i = 0; i < DIMENSION; ++i) { mTuple[i] = tuple.mTuple[i]; } } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> Tuple<DIMENSION,TYPE>::~Tuple () { } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> inline Tuple<DIMENSION,TYPE>::operator const TYPE* () const { return mTuple; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> inline Tuple<DIMENSION,TYPE>::operator TYPE* () { return mTuple; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> inline TYPE Tuple<DIMENSION,TYPE>::operator[] (int i) const { return mTuple[i]; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> inline TYPE& Tuple<DIMENSION,TYPE>::operator[] (int i) { return mTuple[i]; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> Tuple<DIMENSION,TYPE>& Tuple<DIMENSION,TYPE>::operator= (const Tuple& tuple) { for (int i = 0; i < DIMENSION; ++i) { mTuple[i] = tuple.mTuple[i]; } return *this; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> bool Tuple<DIMENSION,TYPE>::operator== (const Tuple& tuple) const { return memcmp(mTuple, tuple.mTuple, DIMENSION*sizeof(TYPE)) == 0; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> bool Tuple<DIMENSION,TYPE>::operator!= (const Tuple& tuple) const { return memcmp(mTuple, tuple.mTuple, DIMENSION*sizeof(TYPE)) != 0; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> bool Tuple<DIMENSION,TYPE>::operator< (const Tuple& tuple) const { return memcmp(mTuple, tuple.mTuple, DIMENSION*sizeof(TYPE)) < 0; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> bool Tuple<DIMENSION,TYPE>::operator<= (const Tuple& tuple) const { return memcmp(mTuple, tuple.mTuple, DIMENSION*sizeof(TYPE)) <= 0; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> bool Tuple<DIMENSION,TYPE>::operator> (const Tuple& tuple) const { return memcmp(mTuple, tuple.mTuple, DIMENSION*sizeof(TYPE)) > 0; } //---------------------------------------------------------------------------- template <int DIMENSION, typename TYPE> bool Tuple<DIMENSION,TYPE>::operator>= (const Tuple& tuple) const { return memcmp(mTuple, tuple.mTuple, DIMENSION*sizeof(TYPE)) >= 0; } //----------------------------------------------------------------------------
.h
codice:// Geometric Tools, LLC // Copyright (c) 1998-2010 // Distributed under the Boost Software License, Version 1.0. // http://www.boost.org/LICENSE_1_0.txt // http://www.geometrictools.com/Licens...ICENSE_1_0.txt // // File Version: 5.0.1 (2010/04/14) #ifndef WM5TUPLE_H #define WM5TUPLE_H #include "Wm5CoreLIB.h" // The class TYPE is either native data or is class data that has the // following member functions: // TYPE::TYPE () // TYPE::TYPE (const TYPE&); // TYPE& TYPE::operator= (const TYPE&) namespace Wm5 { template <int DIMENSION, typename TYPE> class Tuple { public: // Construction and destruction. The default constructor does not // initialize the tuple elements for native elements. The tuple elements // are initialized for class data whenever TYPE initializes during its // default construction. Tuple (); Tuple (const Tuple& tuple); ~Tuple (); // Coordinate access. inline operator const TYPE* () const; inline operator TYPE* (); inline TYPE operator[] (int i) const; inline TYPE& operator[] (int i); // Assignment. Tuple& operator= (const Tuple& tuple); // Comparison. The inequalities make the comparisons using memcmp, thus // treating the tuple as an array of unsigned bytes. bool operator== (const Tuple& tuple) const; bool operator!= (const Tuple& tuple) const; bool operator< (const Tuple& tuple) const; bool operator<= (const Tuple& tuple) const; bool operator> (const Tuple& tuple) const; bool operator>= (const Tuple& tuple) const; protected: TYPE mTuple[DIMENSION]; }; #include "Wm5Tuple.inl" } #endif
come funziona questo esempio?
il problema è che ci sono vari modi da quel che ho capito e ne dovro scegliere uno solo per programmare con i template.
Perchè l'inline è sempre presente coi template?
Mitaly mi ha spiegato a grandi linee cosa fa , ma sono un po incerto.
Sono alle prime armi con i template.

Rispondi quotando