473,382 Members | 1,407 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,382 software developers and data experts.

What's wrong ?? LNK2019 error (Unresolved externals)

To all

I am new to MS's VC++ and got a question.
I've tried to write a simple console program "HelloWorld.cpp", then
I've added a simple class (Class01.h and cpp)

Class01 compile well, but when I want to create an instance inside
HelloWorld.cpp, a LNK2019 error pops up (Unresolved Externals). I
guess somehow the HelloWorld.cpp can't find the Class01 !?

I've added the directory of the Class01.h and .cpp to the options
"Additional Include Directories", but still linking problem.

Expand|Select|Wrap|Line Numbers
  1. // HelloWorld.cpp : Defines the entry point for the console
  2. application.
  3. //
  4. #include "stdafx.h"
  5. #include "Class01.h"
  6.  
  7. using namespace std;
  8.  
  9. void list_CString (const char* oCStr) {
  10. size_t iSize = 0;
  11.  
  12. if (oCStr != NULL) {
  13. iSize =  _tcslen (oCStr);
  14. } else {
  15. iSize = 0;
  16. }
  17.  
  18. cout << "cInput has the following contents : " << endl;
  19. for (size_t i=0; i<iSize; i++) {
  20. cout << oCStr[i] << " ";
  21. }
  22. cout << endl;
  23. }
  24.  
  25. int _tmain(int argc, _TCHAR* argv[])
  26. {
  27. char* cInput = new char[10];
  28. memset (cInput, 0, sizeof (cInput));
  29. cout << "Hello World" << endl;
  30. cin >> cInput;
  31.  
  32. ::list_CString (cInput);
  33. cin >> cInput;
  34.  
  35. Class01* oClass01 = NULL;
  36. oClass01 = new Class01 (); // -- linking error!?
  37.  
  38. return 0;
  39. }
  40.  
  41.  
  42. // -- Class01.h
  43. #include "stdafx.h"
  44. #include <tchar.h>
  45.  
  46. #ifndef _CLASS01_
  47. #define _CLASS01_
  48. // -- cheat the compiler, Class01 is a managed class type !
  49. class Class01 {
  50. public:
  51. // Constructor(s)
  52. Class01 ();
  53.  
  54. // Getter and Setter(s)
  55. void setName (_TCHAR* otc_char);
  56.  
  57. private:
  58. _TCHAR* tc_Name;
  59. #endif
  60. };
  61.  
  62. // -- Class01.cpp
  63. #include "Class01.h"
  64.  
  65. void Class01::setName (_TCHAR* otc_char) {
  66. if (otc_char != NULL) {
  67. tc_Name = otc_char;
  68. } else {
  69. return;
  70. }
  71. }
  72.  
From Jason (Kusanagihk)
Nov 17 '05 #1
2 1074
Thanks pal, after adding the constructor code, it worked!

But another question, as from my code, I have set the cInput (char
array) to only a length of 10, but how come I can enter a string of
more than 20 or even 40 characters ?? (It looks quite illogical, but
somehow it works fine till now)

From Jason (Kusanagihk)
Nov 17 '05 #2
Jason Jacob wrote:
But another question, as from my code, I have set the cInput (char
array) to only a length of 10, but how come I can enter a string of
more than 20 or even 40 characters ?? (It looks quite illogical, but
somehow it works fine till now)


You are overflowing the buffer and stomping on memory you don't own.
Don't do that!!! Really bad things can happen. You are just unlucky
that it seems to have worked so far.

In today's C++, you should never use char arrays to manipulate strings.
Doing so can be really tedious, and it's just too easy to forget how big
your buffer is and write past the end of it. Always use a string class
instead. I prefer std::string, but any class, even CString, is better
than using char arrays.

--
David Olsen
qg********@yahoo.com

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bil Muh | last post by:
Hello Developers, I use VC++ .NET v2003. By using Windows Forms .NET, I am developing an application which will work with TCP/IP functions. I can Build my application in Debug Mode normally, but,...
10
by: Bil Muh | last post by:
Hello Developers, I use VC++ .NET v2003. By using Windows Forms .NET, I am developing an application which will work with TCP/IP functions. I can Build my application in Debug Mode normally, but,...
2
by: rangalo | last post by:
Hi All, I have succeeded in compiling a massive project, originally from vc6 to VS .Net 2005. Now, while linking I am having loads of linker errors with the above code. LNK20019 and LNK2001....
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.