I need help to resolve those error, I try to create a new project it doesn't help
any suggestion?
I got the following errors:
vector_main.obj : error LNK2019: unresolved external symbol "public: __thiscall Vector<int>::~Vector<int>(void)" (??1?$Vector@H@@QAE@XZ) referenced in function _main
vector_main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Vector<int>::setValue(int)" (?setValue@?$Vector@H@@QAEXH@Z) referenced in function _main
vector_main.obj : error LNK2019: unresolved external symbol "public: __thiscall Vector<int>::Vector<int>(int,int)" (??0?$Vector@H@@QAE@HH@Z) referenced in function _main
This is the main function
Expand|Select|Wrap|Line Numbers
- /********************
- * File: vector_main *
- ********************/
- #include <iostream>
- #include <string>
- #include "Vector.h"
- using namespace std;
- void main()
- {
- Vector<int> v1;
- v1.setValue(5);
- }
Expand|Select|Wrap|Line Numbers
- #ifndef _VECTOR_H
- #define _VECTOR_H
- #include <iostream>
- using namespace std;
- template<class T = int>
- class Vector
- {
- private:
- // Data members
- T *m_data;
- int m_size;
- // Private functions
- void reset() { m_size = 0; m_data = NULL; }
- void allocate(int size) { m_size = size; m_data = new T[m_size]; }
- void copy(const T v[]);
- public:
- //Constructors
- explicit Vector(int size = 0, T intVal = T());
- Vector(const Vector& v);
- //Distructor
- ~Vector();
- //Public functions
- int getSize() { return m_size; }
- void setValue(T val);
- //Operators
- Vector& operator=(const Vector &v);
- T& operator[](int i);
- const T& operator[](int i)const;
- //Input/Output (I/O)
- void print(ostream& os=cout)const;
- void read(istream& is);
- };
- #endif
Expand|Select|Wrap|Line Numbers
- /*********************
- * File: Vector.cpp *
- *********************/
- #include <iostream>
- #include "Vector.h"
- using namespace std;
- template<class T>
- Vector<T>::Vector(int size = 0, T intVal = T())
- {
- if (size != 0)
- {
- allocate(size);
- setValue(intVal);
- }
- else
- reset();
- }
- template<class T>
- Vector<T>::Vector(const Vector<T> &v)
- {
- allocate(v.getSize());
- copy(v.m_data);
- }
- template<class T>
- Vector<T>::~Vector()
- {
- delete[] m_data;
- reset();
- }
- template<class T>
- void Vector<T>::setValue(T val)
- {
- for (int i = 0; i < m_size; i++)
- m_data[i] = val;
- }
- template<class T>
- Vector<T>& Vector<T>::operator =(const Vector<T> &v)
- {
- if (this != &v)
- {
- delete[] m_data;
- allocate(v.getSize());
- copy(v.m_data);
- }
- return *this;
- }
- template<class T>
- T& Vector<T>::operator [](int i)
- {
- return m_data[i];
- }
- template<class T>
- const T& Vector<T>::operator [](int i) const
- {
- return m_data[i];
- }
- template<class T>
- void Vector<T>::print(ostream &os = cout) const
- {
- for (int i = 0; i < m_data; i++)
- os<<m_data[i]<<" ";
- }
- template<class T>
- void Vector<T>::read(istream &is)
- {
- for (int i = 0; i < m_data; i++)
- is>>m_data[i];
- }
- template<class T>
- void Vector<T>::copy(const T v[])
- {
- for (int i = 0; i < m_size; i++)
- m_data[i] = v[i];
- }