|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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[i]; } static void *velt(T* l, size_type i) { return (void*)&l[i]; } }; 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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Feb 8, 9:42 am, iceman <jegan...@gmail.com> wrote:
> 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[i]; } > static void *velt(T* l, size_type i) { return (void*)&l[i]; } > > }; > > 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 any particular reason for not using std::vector ? Yuval |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 8 Feb, 08:42, iceman <jegan...@gmail.com> wrote:
> void **_l; > size_type _n; > size_type _capacity; I suggest that you avoid using leading underscores in names. > 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()' As the linker states: You're missing a definition for Vector<void*>::~Vector() |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Feb 8, 10:18 am, yuva...@gmail.com wrote:
> On Feb 8, 9:42 am, iceman <jegan...@gmail.com> wrote: > > > > > 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[i]; } > > static void *velt(T* l, size_type i) { return (void*)&l[i]; } > > > }; > > > 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 > > any particular reason for not using std::vector ? > > Yuval as for your question, the error is because you haven't implemented a destructor to Vector<void*> |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Feb 8, 7:20 pm, yuva...@gmail.com wrote:
> On Feb 8, 10:18 am, yuva...@gmail.com wrote: > > > > > On Feb 8, 9:42 am, iceman <jegan...@gmail.com> wrote: > > > > 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[i]; } > > > static void *velt(T* l, size_type i) { return (void*)&l[i]; } > > > > }; > > > > 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 > > > any particular reason for not using std::vector ? > > > Yuval > > as for your question, the error is because you haven't implemented a > destructor to Vector<void*> But in each class I have implemented a destructor yeah.I wanted to use this in a specific reference to click modular router.Thats why I am using using vector.hh and not std::vector |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 8 Feb, 12:53, iceman <jegan...@gmail.com> wrote:
> On Feb 8, 7:20 pm, yuva...@gmail.com wrote: > > > as for your question, the error is because you haven't implemented a > > destructor to Vector<void*> > > But in each class I have implemented a destructor No you haven't. Look again: template <class T> class Vector { ~Vector(); // no dtor body }; template <> class Vector<void*> { ~Vector(); // **** no dtor body **** }; template <class T> class Vector<T*>: private Vector<void*> { ~Vector() { } // dtor body }; The error message is telling you there's no body for Vector<void*>::~Vector() |
|
![]() |
| Outils de la discussion | |
|
|