Thread: Link Error : unresolved external symbol "public: __thiscall"

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Link Error : unresolved external symbol "public: __thiscall"

    Ok this is not gonna be a simple one to explain since few classes are involved ... But, i'm goona start with the main class

    Code:
    #include "Fleet.h"
    #include "Menu.h"
    #include "Rental.h"
    #include <conio.h>
    
    using namespace std;
    
    /* ------------------------------------------------------------------------------------------------
    * Main
    */
    int main()
    {
    	Fleet fleet;
    	Rental rental;
    
    /*** Create and Add Menu Items to the Menu list ***/
    
    	Menu menu(fleet, rental);
    	menu.CreateMainMenu();
    	menu.CreateFleetMenu();
    	menu.StartScreen();
    	menu.toFleetMenu(false);
    
    /*** Execute menu until user quits.... ***/
    	
    	do {
    		menu.choose();
    	}
    	while (!menu.done());
    
    	return 0;
    }
    /*** ERROR ****/
    error LNK2019: unresolved external symbol "public: __thiscall Rental::~Rental(void)" (??1Rental@@QAE@XZ) referenced in function _main
    error LNK2019: unresolved external symbol "public: __thiscall Rental::Rental(void)" (??0Rental@@QAE@XZ) referenced in function _main
     : fatal error LNK1120: 2 unresolved externals
    */
    
    Class Rental

    Code:
    #include "Contract.h"
    #include <vector>
    
    class Driver;
    
    class Rental
    {
    private:
    	typedef std::vector<Contract> RentalContract;
    	typedef RentalContract::iterator ContractsIterator;
    
    public:
    
    	Rental();
    	Rental(Driver&);
    	~Rental();
    
    	//RentalContract getRental();
    
    	void CreateNewContract();
    	void DeleteContract();
    	void ViewContract();
    	ContractsIterator find(); 
    	
    private:
    	RentalContract contracts;
    	Driver &driver;
    };
    
    /** Part of its CPP **/
    
    include "Rental.h"
    #include "Driver.h"
    #include <iostream>
    #include <algorithm>
    #include <conio.h>
    
    Rental::Rental(Driver& d) :
    driver(d)
    {}
    Let me stop here perhaps you may pick up the fault already ...

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need to compile all your .cpp files together.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    My guess is that you forgot to implement the default constructor and destructor of Rental despite declaring them. Since you have a reference member, you would need to implement the Rental default constructor, but it looks like the compiler generated destructor will do.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by laserlight View Post
    My guess is that you forgot to implement the default constructor and destructor of Rental despite declaring them. Since you have a reference member, you would need to implement the Rental default constructor, but it looks like the compiler generated destructor will do.
    Well i did this Rental::Rental() {} but then i get an error

    Code:
    : error C2758: 'Rental::driver' : must be initialized in constructor base/member initializer list
    Tried the following to solve the error
    Code:
    Rental::Rental(Driver& d) :
    driver(d)
    {}
    
    Rental::Rental():
    driver()
    {}
    but got this error
    Code:
    : error C2354: 'Rental::driver' : initialization of reference member requires a temporary variable
    Last edited by csonx_p; 08-26-2008 at 12:30 PM.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Since driver is a reference, it must be bound to something. If you want to have a Rental without a driver like this, then you can't use references (presumably you meant to have a pointer?).

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Solved my problem,

    Code:
    	Driver driver;
    	Rental rental(driver);
    My stupidity really ... /bangs his head hard against the wall ~^*

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    driver is a reference, so it must refer to something. You can either choose to change driver to a pointer (or an object, but it may not make sense for a Rental object to own a Driver object), or simply only allow Rental objects to be constructed with a driver (in which case the code of your main() function must change).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM