I'm trying to make a little vector type thing but I get 5 errors when trying to compile the following code, I've never really used templates before ;_;
Here's the code:
Code:
#include <iostream.h>
#include <stdarg.h>
template <class hndl>
class myvector {
public:
hndl *vectype;
myvector(int basesize = 1);
~myvector();
hndl getaverage (void);
void resize (int newsize);
void set_v (int start, int finish, ...);
void output (ostream & location);
void output (int start, int finish, ostream & location);
int getsize (void);
int getmid (void);
int getlow (int start);
private:
int size;
};
hndl myvector::myvector(int basesize)
{
vectype = new hndl [basesize];
size = basesize;
}
hndl myvector::~myvector()
{
delete [] vectype;
vectype = NULL;
}
void myvector::resize(int newsize)
{
delete [] vectype;
vectype = new hndl [newsize];
size = newsize;
}
hndl myvector::getaverage(void)
{
auto int i;
hndl t;
for (i = 0; i < size; ++i)
t += vectype[i];
t /= size;
return (t);
}
int myvector::getlow(int start)
{
int lowspot = start;
for (auto int c = start; c < size; ++c) {
if (vectype[c] < vectype[lowspot])
lowspot = c;
}
return lowspot;
}
int myvector::getmid(void)
{
return int(size/2);
}
void myvector:: output(int start, int finish, ostream &location)
{
for (int i = start; i < finish; ++i)
cout << vectype[i] << ", ";
}
void myvector:: output(ostream & location)
{
for (int i = 0; i < size; ++i)
cout << vectype[i] << ", ";
}
void myvector::set_v(int start, int finish, ...)
{
va_list args;
va_start (args, nm);
for (int i = st; i < nm; ++i) {
vectype[i] = va_arg(args, hndl);
}
va_end (args);
}
And taking the "hndl" out before the constructor/deconstructor creates maaaaaaaannnnnny errors... ;_;