p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Visual C++ 2005 (http://p2p.wrox.com/forumdisplay.php?f=139)
-   -   Unresolved External Symbol - LNK2019 (http://p2p.wrox.com/showthread.php?t=41288)

Valke April 14th, 2006 11:47 AM

Unresolved External Symbol - LNK2019
 
Hi,
I have just started programming with C using Visual C++. At the moment I am learning how to handle classes. I am using a C++ book, where I am instructed to create applications that use classes like this:

Person.h
#pragma once

class Person
{
private:
    char name[30];
    int age;
public:
    Person();
};


ClassPerson.h
#include "stdafx.h"
using namespace std;

Person::Person()
{
    name = "Name";
    age = 15;
}


stdafx.h
#pragma once


#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include "Person.h"


Person.cpp

#include "stdafx.h"
using namespace std;

void main()
{
    Person person;
    cin.get();
}

This is not working. I get an unresolved external symbol LNK2019 error:
Person.obj : error LNK2019: unresolved external symbol "public: __thiscall Person::Person(void)" (??0Person@@QAE@XZ) referenced in function _main

I have made the example here as simple as possible. I have searched MSDN and other resources how to resolve the issue, but I don't fully understand what to do. So, can somebody please instruct what changes I should make in the code?

The only way to solve this so far, is to put ALL code in a single cpp-file. Also if I comment out the Person person; line, the application will run.
Thank you for your assistance.

Cheers!


Valke April 14th, 2006 02:44 PM

Problem solved. ClassPerson.cpp (ClassPerson.h by mistake on text above) was not compiled.



All times are GMT -4. The time now is 08:24 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.