Right. SG's suggestion was to use std::vector to implement your Vector class.
"class T" works just fine. In this context, they're interchangable.
Some people think "class T" is confusing because T doesn't actually
have to be a class, but that's too pedantic for my taste.
--
Pete
Roundhouse Consulting, Ltd. (
www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(
www.petebecker.com/tr1book)
If you hated the code that was posted on Pastebin, you are definitely
going to dislike this bit of code I whipped up.
typedef unsigned int unt; // unsigned integer
/* Superprimary template? */
template <unt N, typename T, unt M, typename S>
class Vector<N,T>
{
public:
Vector<N,T>(); // All elements in T* have a numeric value of
zero
Vector<N,T>(const T*); // There should be N number of elements in
T*, otherwise they are set to zero. If there are more than N
elements, they are ignored.
Vector<N,T>(const S*); // If S is of a different type, but still
has N number of elements, convert the S values to T type and fill in
the blanks with zeros.
Vector<N,T>(const Vector<N,T>&); // Copy Constructor
Vector<N,T>(const Vector<M,T>&); // Copy Constructor, same type but
different number of elements. If N > M, the blanks are filled with
zeros. If N < M, only the first values Vector<M,T> are put into
Vector<N,T>. If N = M, it should just call the copy constructor.
Vector<N,T>(const Vector<M,S>&); // Copy Constructor, different
number of elements and different types. Same rules as the previous
copy constructor but with some typecasting.
virtual ~Vector<N,T>(); // Deconstructor, virtual for polymorphism
// Eventually, define the == and != ?
Vector<N,T>& operator=(const T*);
Vector<N,T>& operator=(const S*);
Vector<N,T>& operator=(const Vector<N,T>&);
Vector<N,T>& operator=(const Vector<M,T>&);
Vector<N,T>& operator=(const Vector<M,S>&);
Vecotr<N,T>& set(const unt,const T&); // set a value in the Vector
Vector<N,T>& set(const unt,const S&); // set a value in the Vector
that is of a different type. (Assuming this is possible. This will
typecast the S value to a T value)
T get(const unt) const; // get a specific value
T* get() const; // get the set of values from a vector.
//unt index(const T&) const; // find the first instance of a
specific value.
void print() const; // print out the values of the data
structure
//void print(std::fout) const; // Print the values to some file.
(Eventually I'll write this up.)
private:
unt i = N; // number of elements
T* t; // list of elements
}
Remember, I'm not using the C++ vector class. This is something I'm
working on to work with numerical data structures for mathematic and
scientific models.