473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error: "Unresolved external symbol"

Hi Everyone, I'm having a problem compiling useing the VS2005 .NET

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
  1. /********************
  2. * File: vector_main *
  3. ********************/
  4.  
  5. #include <iostream>
  6. #include <string>
  7. #include "Vector.h"
  8.  
  9. using namespace std;
  10.  
  11.  
  12. void main()
  13. {
  14.     Vector<int> v1;    
  15.     v1.setValue(5);
  16. }
  17.  
  18.  
This is the class declaration Vector.h

Expand|Select|Wrap|Line Numbers
  1.  
  2. #ifndef _VECTOR_H
  3. #define _VECTOR_H
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. template<class T = int>
  9. class Vector
  10. {
  11. private:
  12.     // Data members
  13.     T *m_data;
  14.     int m_size;
  15.  
  16.     // Private functions
  17.     void reset() { m_size = 0; m_data = NULL; }
  18.     void allocate(int size) { m_size = size; m_data = new T[m_size]; } 
  19.     void copy(const T v[]);
  20.  
  21. public:
  22.  
  23.     //Constructors
  24.     explicit Vector(int size = 0, T intVal = T());
  25.  
  26.     Vector(const Vector& v);
  27.  
  28.  
  29.     //Distructor
  30.     ~Vector();
  31.  
  32.     //Public functions
  33.     int getSize() { return m_size; }
  34.  
  35.     void setValue(T val);
  36.  
  37.     //Operators
  38.     Vector& operator=(const Vector &v);
  39.  
  40.     T& operator[](int i);
  41.  
  42.     const T& operator[](int i)const;
  43.  
  44.     //Input/Output (I/O)
  45.     void print(ostream& os=cout)const;
  46.     void read(istream& is);
  47. };
  48.  
  49. #endif
  50.  
and this is the impementation file Vector.cc
Expand|Select|Wrap|Line Numbers
  1.  
  2. /*********************
  3. * File: Vector.cpp *
  4. *********************/
  5.  
  6. #include <iostream>
  7. #include "Vector.h"
  8.  
  9. using namespace std;
  10.  
  11.  
  12. template<class T>
  13. Vector<T>::Vector(int size = 0, T intVal = T())
  14. {
  15.     if (size != 0)
  16.     {
  17.         allocate(size);
  18.         setValue(intVal);
  19.     }
  20.     else
  21.         reset();
  22. }
  23.  
  24. template<class T>
  25. Vector<T>::Vector(const Vector<T> &v)
  26. {
  27.     allocate(v.getSize());
  28.     copy(v.m_data);
  29. }
  30.  
  31. template<class T>
  32. Vector<T>::~Vector()
  33. {
  34.     delete[] m_data;
  35.     reset();
  36. }
  37.  
  38. template<class T>
  39. void Vector<T>::setValue(T val)
  40. {
  41.     for (int i = 0; i < m_size; i++)
  42.         m_data[i] = val;
  43. }
  44.  
  45. template<class T>
  46. Vector<T>& Vector<T>::operator =(const Vector<T> &v)
  47. {
  48.     if (this != &v)
  49.     {
  50.         delete[] m_data;
  51.         allocate(v.getSize());
  52.         copy(v.m_data);
  53.     }
  54.     return *this;
  55. }
  56.  
  57. template<class T>
  58. T& Vector<T>::operator [](int i)
  59. {
  60.     return m_data[i];
  61. }
  62.  
  63. template<class T>
  64. const T& Vector<T>::operator [](int i) const
  65. {
  66.     return m_data[i];
  67. }
  68.  
  69. template<class T>
  70. void Vector<T>::print(ostream &os = cout) const
  71. {
  72.     for (int i = 0; i < m_data; i++)
  73.         os<<m_data[i]<<" ";
  74. }
  75.  
  76. template<class T>
  77. void Vector<T>::read(istream &is)
  78. {
  79.     for (int i = 0; i < m_data; i++)
  80.         is>>m_data[i];
  81. }
  82.  
  83. template<class T>
  84. void Vector<T>::copy(const T v[])
  85. {
  86.     for (int i = 0; i < m_size; i++)
  87.             m_data[i] = v[i]; 
  88. }
  89.  
  90.  
  91.  
Sep 7 '07 #1
7 3077
Please, I need your help...
anyone fimilar with this problem and knows what could be the reason for such an error

-------------------------------------------------------------------------------------------------------------------

Hi Everyone, I'm having a problem compiling useing the VS2005 .NET

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
  1. /********************
  2. * File: vector_main *
  3. ********************/
  4.  
  5. #include <iostream>
  6. #include <string>
  7. #include "Vector.h"
  8.  
  9. using namespace std;
  10.  
  11.  
  12. void main()
  13. {
  14.     Vector<int> v1;    
  15.     v1.setValue(5);
  16. }
  17.  
  18.  
This is the class declaration Vector.h

Expand|Select|Wrap|Line Numbers
  1.  
  2. #ifndef _VECTOR_H
  3. #define _VECTOR_H
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. template<class T = int>
  9. class Vector
  10. {
  11. private:
  12.     // Data members
  13.     T *m_data;
  14.     int m_size;
  15.  
  16.     // Private functions
  17.     void reset() { m_size = 0; m_data = NULL; }
  18.     void allocate(int size) { m_size = size; m_data = new T[m_size]; } 
  19.     void copy(const T v[]);
  20.  
  21. public:
  22.  
  23.     //Constructors
  24.     explicit Vector(int size = 0, T intVal = T());
  25.  
  26.     Vector(const Vector& v);
  27.  
  28.  
  29.     //Distructor
  30.     ~Vector();
  31.  
  32.     //Public functions
  33.     int getSize() { return m_size; }
  34.  
  35.     void setValue(T val);
  36.  
  37.     //Operators
  38.     Vector& operator=(const Vector &v);
  39.  
  40.     T& operator[](int i);
  41.  
  42.     const T& operator[](int i)const;
  43.  
  44.     //Input/Output (I/O)
  45.     void print(ostream& os=cout)const;
  46.     void read(istream& is);
  47. };
  48.  
  49. #endif
  50.  
and this is the impementation file Vector.cc
Expand|Select|Wrap|Line Numbers
  1.  
  2. /*********************
  3. * File: Vector.cpp *
  4. *********************/
  5.  
  6. #include <iostream>
  7. #include "Vector.h"
  8.  
  9. using namespace std;
  10.  
  11.  
  12. template<class T>
  13. Vector<T>::Vector(int size = 0, T intVal = T())
  14. {
  15.     if (size != 0)
  16.     {
  17.         allocate(size);
  18.         setValue(intVal);
  19.     }
  20.     else
  21.         reset();
  22. }
  23.  
  24. template<class T>
  25. Vector<T>::Vector(const Vector<T> &v)
  26. {
  27.     allocate(v.getSize());
  28.     copy(v.m_data);
  29. }
  30.  
  31. template<class T>
  32. Vector<T>::~Vector()
  33. {
  34.     delete[] m_data;
  35.     reset();
  36. }
  37.  
  38. template<class T>
  39. void Vector<T>::setValue(T val)
  40. {
  41.     for (int i = 0; i < m_size; i++)
  42.         m_data[i] = val;
  43. }
  44.  
  45. template<class T>
  46. Vector<T>& Vector<T>::operator =(const Vector<T> &v)
  47. {
  48.     if (this != &v)
  49.     {
  50.         delete[] m_data;
  51.         allocate(v.getSize());
  52.         copy(v.m_data);
  53.     }
  54.     return *this;
  55. }
  56.  
  57. template<class T>
  58. T& Vector<T>::operator [](int i)
  59. {
  60.     return m_data[i];
  61. }
  62.  
  63. template<class T>
  64. const T& Vector<T>::operator [](int i) const
  65. {
  66.     return m_data[i];
  67. }
  68.  
  69. template<class T>
  70. void Vector<T>::print(ostream &os = cout) const
  71. {
  72.     for (int i = 0; i < m_data; i++)
  73.         os<<m_data[i]<<" ";
  74. }
  75.  
  76. template<class T>
  77. void Vector<T>::read(istream &is)
  78. {
  79.     for (int i = 0; i < m_data; i++)
  80.         is>>m_data[i];
  81. }
  82.  
  83. template<class T>
  84. void Vector<T>::copy(const T v[])
  85. {
  86.     for (int i = 0; i < m_size; i++)
  87.             m_data[i] = v[i]; 
  88. }
  89.  
  90.  
  91.  
Sep 7 '07 #2
RRick
463 Expert 256MB
What compiler are you using?
Sep 7 '07 #3
RRick
463 Expert 256MB
Oops. Sorry, I missed the compiler definition in your message
Sep 7 '07 #4
Oops. Sorry, I missed the compiler definition in your message

[TEXT=JustBeSimple]
Hi, I just notice that if I implenet all in the "Vector.h" file, so its ok
so probably the problem is how I declare it in my "Vector.cpp" file
[/TEXT]
Sep 7 '07 #5
RRick
463 Expert 256MB
That was the reason for my original question. Some compilers (GNU g++) must have all the "template" code in the header file, no exceptions.

I thought windows didn't have this problem. Maybe somebody else knows for certain.

Just a simple stupid question: Did you make sure the vector.o file was included in the link? Once again, I thought VS took care of this.
Sep 8 '07 #6
That was the reason for my original question. Some compilers (GNU g++) must have all the "template" code in the header file, no exceptions.

I thought windows didn't have this problem. Maybe somebody else knows for certain.

Just a simple stupid question: Did you make sure the vector.o file was included in the link? Once again, I thought VS took care of this.
Where can see if the "Vector.o" file was included in the link?
Or can I set it?
Sep 8 '07 #7
Where can see if the "Vector.o" file was included in the link?
Or can I set it?
Ok, its normal behavor you can look at this link for the solution and/or the reason it happening


Thanks any way
Sep 8 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rodolphe | last post by:
Hello, I'm French so sorry for my approximate English. When I try to compile a project under Visual C++ 6.0, I've got the following errors : applicap.obj : error LNK2001: unresolved external...
4
by: Mastadex | last post by:
So here is my Code: template <class T> struct Nodes { T *Data; // The Image char Name; // The Name of the image Nodes<T> *Prev; Nodes<T> *Next;
4
by: naveenadevi | last post by:
Hi, I'm trying to use some power management features with windowsx xp and I have visual studio .net 2003 installed. As per documentation of ACPI, you can use the power options by including...
1
by: Awin | last post by:
Hello all, I'm a beginner of COM programming, I have a exercise, but got a compile error with ComFortuneTeller.obj : error LNK2001: unresolved external symbol _IID_IQuotation...
0
by: Simon | last post by:
Hi All, I have come across a problem with a bog std MFC app linking to bog std MFC extension dll - both generated by the wizards. The code is set out below. The trouble is with the static...
1
by: karthikvis | last post by:
Hi, I would really appreciate it of someone could help me. I tried compiling a source code which references header files from another directory on my hard disk (not the default VC++ header files...
0
by: =?Utf-8?B?TWF0ZXVzeiBSYWpjYQ==?= | last post by:
Hi! How can I fix this error? Error 1 error LNK2001: unresolved external symbol "extern "C" long __stdcall SHFlushClipboard(void)" (?SHFlushClipboard@@$$J10YGJXZ) UnmanagedTest.obj Basically...
8
by: amievil | last post by:
Hello. I'm devloping MFC program and found something weird happening. When I compile it with "debug mode", it compile fine, and runs fine. however, when I compile with "release mode", I get...
0
by: Nilam2477 | last post by:
I have an application which is converted from VC6 to VC7.1 (.net 2003) I'm trying to debug in .net 2003 i need to check the return value HRESULT value. I have declared hr as HRESULT hr = S_OK;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.