error in using vectors

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
 
Y

yuvalif

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


any particular reason for not using std::vector ?

Yuval
 
T

Triple-DES

  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()
 
Y

yuvalif

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;

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

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*>
 
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

any particular reason for not using std::vector ?

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
 
T

tragomaskhalos

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top