PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > error in using vectors
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
error in using vectors

Réponse
 
LinkBack Outils de la discussion
Vieux 08/02/2008, 07h42   #1
iceman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut error in using vectors

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

  Réponse avec citation
Vieux 08/02/2008, 08h18   #2
yuvalif@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: error in using vectors

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
  Réponse avec citation
Vieux 08/02/2008, 08h20   #3
Triple-DES
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: error in using vectors

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()
  Réponse avec citation
Vieux 08/02/2008, 08h20   #4
yuvalif@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: error in using vectors

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*>
  Réponse avec citation
Vieux 08/02/2008, 12h53   #5
iceman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: error in using vectors

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
  Réponse avec citation
Vieux 08/02/2008, 13h26   #6
tragomaskhalos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: error in using vectors

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





  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h02.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17856 seconds with 14 queries