J
Jason Jacob
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.
From Jason (Kusanagihk)
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.
Code:
// HelloWorld.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include "Class01.h"
using namespace std;
void list_CString (const char* oCStr) {
size_t iSize = 0;
if (oCStr != NULL) {
iSize = _tcslen (oCStr);
} else {
iSize = 0;
}
cout << "cInput has the following contents : " << endl;
for (size_t i=0; i<iSize; i++) {
cout << oCStr[i] << " ";
}
cout << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
char* cInput = new char[10];
memset (cInput, 0, sizeof (cInput));
cout << "Hello World" << endl;
cin >> cInput;
::list_CString (cInput);
cin >> cInput;
Class01* oClass01 = NULL;
oClass01 = new Class01 (); // -- linking error!?
return 0;
}
// -- Class01.h
#include "stdafx.h"
#include <tchar.h>
#ifndef _CLASS01_
#define _CLASS01_
// -- cheat the compiler, Class01 is a managed class type !
class Class01 {
public:
// Constructor(s)
Class01 ();
// Getter and Setter(s)
void setName (_TCHAR* otc_char);
private:
_TCHAR* tc_Name;
#endif
};
// -- Class01.cpp
#include "Class01.h"
void Class01::setName (_TCHAR* otc_char) {
if (otc_char != NULL) {
tc_Name = otc_char;
} else {
return;
}
}
From Jason (Kusanagihk)