Thread: Spotting the error...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    2

    Spotting the error...

    For the life of me I can't spot any error in this piece of code, i've started a small piece, so I compiled it to check if it was all good. But it comes out with an error

    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    
    using namespace std;
    
    class employee
    {
    	private:
    		int number;
    		float salary;
    		string fname;
    		string lname;
    
    	public:
    		employee(int num, float sal, string first, string last);
    		employee();
    		~employee();
    
    		int getnumber();
    		float getsalary();
    		string getfname();
    		string getlname();
    
    		void setfname(string newfname);
    		void setlname(string newlname);
    };
    
    employee::employee(int num, float sal, string first, string last)
    {
    	num = 0;
    	sal = 0.00;
    	first = "Default";
    	last = "Default";
    }
    
    employee::~employee()
    {}
    
    int employee::getnumber()
    {
    	return number;
    }
    
    float employee::getsalary()
    {
    	return salary;
    }
    
    string employee::getfname()
    {
    	return fname;
    }
    
    string employee::getlname()
    {
    	return lname;
    }
    
    void employee::setfname(string newfname)
    {
    	fname = newfname;
    }
    
    void employee::setlname(string newlname)
    {
    	lname = newlname;
    }
    
    void main()
    {
    	employee List[2];
    
    	int Number = 0;
    	float Salary = 0;
    	string firstName = "Default";
    	string lastName = "Default";
    }
    The error is
    1>------ Build started: Project: Assignment2V1_Correct, Configuration: Debug Win32 ------
    1>Compiling...
    1>Assignment2_Correct.cpp
    1>Compiling manifest to resources...
    1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
    1>Copyright (C) Microsoft Corporation. All rights reserved.
    1>Linking...
    1>Assignment2_Correct.obj : error LNK2019: unresolved external symbol "public: __thiscall employee::employee(void)" (??0employee@@QAE@XZ) referenced in function _main
    1>C:\Users\anonymous\Documents\Programming\C++\Ass ignment2V1_Correct\Debug\Assignment2V1_Correct.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\Users\anonymous\Documents\Programming\C++\Assig nment2V1_Correct\Assignment2V1_Correct\Debug\Build Log.htm"
    1>Assignment2V1_Correct - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    If anyone could hint me towards the solution that'd be great...thanks

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    The Employee constructor without parameters is declared to exist, used by main, but doesn't exist... That's what it's complaining about.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You did not define a default constructor, and yet you default construct two employee objects on this line:
    Code:
    employee List[2];
    Normally, the compiler will define a default constructor if it is required and yet not provided, but here that does not happen since you declared some other constructor.
    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
    Nov 2008
    Posts
    2
    Many thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM