I
iceman
Hi All,
I am using a header file called vector.hh
#ifndef VECTOR_HH
#define VECTOR_HH
#include <assert.h>
template <class T>
class Vector { public:
typedef T value_type;
typedef T& reference;
typedef const T& const_reference;
typedef T* pointer;
typedef const T* const_pointer;
typedef int size_type;
typedef T* iterator;
typedef const T* const_iterator;
explicit Vector() : _l(0), _n(0), _capacity(0) { }
explicit Vector(size_type n, const T &e) : _l(0), _n(0),
_capacity(0) { resize(n, e); }
// template <class In> ...
Vector(const Vector<T> &);
~Vector();
private:
T *_l;
size_type _n;
size_type _capacity;
void *velt(size_type i) const { return (void*)&_l; }
static void *velt(T* l, size_type i) { return (void*)&l; }
};
template <>
class Vector<void*> { public:
typedef void* value_type;
typedef void*& reference;
typedef void* const& const_reference;
typedef void** pointer;
typedef void* const* const_pointer;
typedef int size_type;
typedef void** iterator;
typedef void* const* const_iterator;
explicit Vector() : _l(0), _n(0), _capacity(0) { }
explicit Vector(size_type n, void* e) : _l(0), _n(0), _capacity(0)
{}// resize(n, e); }
Vector(const Vector<void*> &);
~Vector();
private:
void **_l;
size_type _n;
size_type _capacity;
};
template <class T>
class Vector<T*>: private Vector<void*> {
typedef Vector<void*> Base;
public:
typedef T* value_type;
typedef T*& reference;
typedef T* const& const_reference;
typedef T** pointer;
typedef T* const* const_pointer;
typedef int size_type;
typedef T** iterator;
typedef T* const* const_iterator;
explicit Vector() : Base() { }
explicit Vector(size_type n, T* e) : Base(n, (void *)e) { }
Vector(const Vector<T *> &o) : Base(o) { }
~Vector() { }
};
and my main is
#include <vector.hh>
int main()
{
Vector<int *> x;
}
I am able to compile it but when I link I am getting the error
test.o: In function `Vector<int*>::~Vector()':
test.cpp.text._ZN6VectorIPiED1Ev[Vector<int*>::~Vector()]+0xd):
undefined reference to `Vector<void*>::~Vector()'
collect2: ld returned 1 exit status
I have been stuck with this for a long time but I have not found a
solution so far
Cheers
I am using a header file called vector.hh
#ifndef VECTOR_HH
#define VECTOR_HH
#include <assert.h>
template <class T>
class Vector { public:
typedef T value_type;
typedef T& reference;
typedef const T& const_reference;
typedef T* pointer;
typedef const T* const_pointer;
typedef int size_type;
typedef T* iterator;
typedef const T* const_iterator;
explicit Vector() : _l(0), _n(0), _capacity(0) { }
explicit Vector(size_type n, const T &e) : _l(0), _n(0),
_capacity(0) { resize(n, e); }
// template <class In> ...
Vector(const Vector<T> &);
~Vector();
private:
T *_l;
size_type _n;
size_type _capacity;
void *velt(size_type i) const { return (void*)&_l; }
static void *velt(T* l, size_type i) { return (void*)&l; }
};
template <>
class Vector<void*> { public:
typedef void* value_type;
typedef void*& reference;
typedef void* const& const_reference;
typedef void** pointer;
typedef void* const* const_pointer;
typedef int size_type;
typedef void** iterator;
typedef void* const* const_iterator;
explicit Vector() : _l(0), _n(0), _capacity(0) { }
explicit Vector(size_type n, void* e) : _l(0), _n(0), _capacity(0)
{}// resize(n, e); }
Vector(const Vector<void*> &);
~Vector();
private:
void **_l;
size_type _n;
size_type _capacity;
};
template <class T>
class Vector<T*>: private Vector<void*> {
typedef Vector<void*> Base;
public:
typedef T* value_type;
typedef T*& reference;
typedef T* const& const_reference;
typedef T** pointer;
typedef T* const* const_pointer;
typedef int size_type;
typedef T** iterator;
typedef T* const* const_iterator;
explicit Vector() : Base() { }
explicit Vector(size_type n, T* e) : Base(n, (void *)e) { }
Vector(const Vector<T *> &o) : Base(o) { }
~Vector() { }
};
and my main is
#include <vector.hh>
int main()
{
Vector<int *> x;
}
I am able to compile it but when I link I am getting the error
test.o: In function `Vector<int*>::~Vector()':
test.cpp.text._ZN6VectorIPiED1Ev[Vector<int*>::~Vector()]+0xd):
undefined reference to `Vector<void*>::~Vector()'
collect2: ld returned 1 exit status
I have been stuck with this for a long time but I have not found a
solution so far
Cheers