Thread: Help with: error LNK2019: unresolved external symbol

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    329

    Help with: error LNK2019: unresolved external symbol

    Hi,

    I'm just learning about Struct and have written this very simple code:

    Code:
    #include <iostream>
    #include <iomanip>
    #include <vector>
    #include <ios>
    #include <string>
    #include <algorithm>
    #include "header.h"
    #include <stdexcept>
    #include <cctype>
    
    using namespace std;
    
    struct Date {
    
    	int y, m, d;
    	Date(int y, int m, int d);
    	void add_day(int n);
    };
    
    
    
    int main()
    {
    
    	Date today(2010, 06, 16);
    
    	cin.get();
    
    	return 0;
    }
    But it won't compile and I get the following error:

    test.obj : error LNK2019: unresolved external symbol "public: __thiscall Date:ate(int,int,int)" (??0Date@@QAE@HHH@Z) referenced in function _main

    Any ideas please?

    Thanks.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    struct Date {
    
        int y, m, d;
        Date(int y, int m, int d);
        void add_day(int n);
    };
    The bolded line above declares a constructor for the struct.


    Code:
    int main()
    {
    
        Date today(2010, 06, 16);
    The bolded line above calls the constructor. The problem is you haven't defined the constructor anywhere in your code. You need to actually create the function that you've said exists and are trying to call.

    It's like you create a function prototype and call that function but you haven't actually written any code for the function:
    Code:
    int foo(int bar);  <- Prototype the function "foo"
    
    int main()
    {
        foo(1);  <- Call function already prototyped but where is the actual function code?
        return 0;
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Thanks for the response. Will try that shortly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM