Hi. i 'm learning C++...Now i need some help for my code because i get this error

error LNK2019: unresolved external symbol "public: __thiscall Parkedcar::Parkedcar(void)" (??0Parkedcar@@QAE@XZ) referenced in function _wmain
1>C:\Users\jackkwok\Documents\Visual Studio 2005\Projects\KwokParking\Debug\KwokParking.exe : fatal error LNK1120: 1 unresolved externals

Please let me know how to fix this problem. thanks in advance

#ifndef	PARKEDCAR_H
#define PARKEDCAR_H
#include <iostream>
#include <string>
using namespace std;

class Parkedcar
{
private:
	string make;	// Holds make of parked car
	string model;	// Holds model of parked car
	string color;	// Holds color of parked car
	string licNum;	// Holds license number of parked car
	int minParked;	// Holds minutes of parked car
public:
	Parkedcar();	// Constructor

	void setMake(string pcMake)
	{
		make = pcMake;
	}
	void setModel(string pcModel)
	{
		model = pcModel;
	}
	void setColor(string pcColor)
	{
		color = pcColor;
	}
	void setLicNum(string pcLicNum)
	{
		licNum = pcLicNum;
	}
	void setMinParked(int pcMin)
	{
		minParked = pcMin;
	}
	
	string getMake()
	{
		return make;
	}
	string getModel()
	{
		return model;
	}
	string getColor()
	{
		return color;
	}
	string getLicNum()
	{
		return licNum;
	}
	int getMinParked()
	{
		return minParked;
	}
	

};
#endif

#ifndef PARKINGMETER_H
#define PARKINGMETER_H
#include <string>
#include <iostream>
using namespace std;

class ParkingMeter
{
	private: 
		int minPurchased;
	public:
		
		ParkingMeter(int mPurchased)
		{
			minPurchased = mPurchased;
		}

		void setMinutesPurchased(int mPurchased)
		{
			minPurchased = mPurchased;
		}
		int getMinPurchased()
		{
			return minPurchased;
		}

		void print ()const
		{
			cout << " Minutes of parking time that has been purchased: " << endl;
		}
};
#endif

#ifndef	PARKINGTICKET_H
#define PARKINGTICKET_H
#include <iostream>
#include <string>
using namespace std;

class ParkingTicket
{
private:
	string make;			// Holds make of parked car
	string model;			// Holds make of parked car
	string color;			// Holds make of parked car
	string licNum;			// Holds make of parked car
	string officerName;		// Holds name of police officer
	string badgeNum;		// Holds badge number of police officer
	int minParked;			// Holds time that car has been parked
	int minPurchased;		// Holds time purchased at parking meter
	int difference;			// Holds time 
public:
	ParkingTicket();
		
	void setMake(string ptMake)
	{
		make = ptMake;
	}
	void setModel(string ptModel)
	{
		model = ptModel;
	}
	void setColor(string ptColor)
	{
		color = ptColor;
	}
	void setLicNum(string ptLicNum)
	{
		licNum = ptLicNum;
	}
	void setOfficerName(string ptOffName)
	{
		officerName = ptOffName;
	}
	void setBadgeNum(string ptBadgeNum)
	{
		badgeNum = ptBadgeNum;
	}
	void setMinParked(int minPark)
	{
		minParked = minPark;
	}
	void setMinPurchased(int minPurchase)
	{
		minPurchased = minPurchase;
	}
	void setDifference(int diff)
	{
		difference = diff;
	}
	string getMake()
	{
		return make;
	}
	string getModel()
	{
		return model;
	}
	string getColor()
	{
		return color;
	}
	string getLicNum()
	{
		return licNum;
	}
	string getOfficerName()
	{
		return officerName;
	}
	string getBadgeNum()
	{
		return badgeNum;
	}
	int getMinParked()
	{
		return minParked;
	}
	int getMinPurchased()
	{
		return minPurchased;
	}
	int getDifference()
	{
		return difference;
	}
};
#endif

#ifndef	POLICEOFFICER_H
#define POLICEOFFICER_H
#include <iostream>
#include <string>
using namespace std;

class PoliceOfficer
{
private:
	string officerName;		// Holds name of police officer
	string badgeNum;		// Holds badge number of police officer
public:
	PoliceOfficer();

	void setOfficerName(string poOffName)
	{
		officerName = poOffName;
	}
	void setBadgeNum(string poBadgeNum)
	{
		badgeNum = poBadgeNum;
	}
	string getOfficerName()
	{
		return officerName;
	}
	string getBadgeNum()
	{
		return badgeNum;
	}
};
#endif

cpp.file
#include "stdafx.h"
#include "ParkingMeter.h"
#include "Parkedcar.h"
#include "Parkingticket.h"
#include "PoliceOfficer.h"
#include <iostream>
#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	
	// Create a Car object.
	Parkedcar car;
	car.setMake("Ford");
	car.setModel("Mustang");
	car.setColor("Purple");
	car.setLicNum("JKL123");
	car.setMinParked(125);
		return 0;


	cout << " Make: " << car.getMake() << endl;
	cout << " Model: " << car.getModel() << endl;
	cout << " Color: " << car.getColor() << endl;
	cout << " License Number: " << car.getLicNum() << endl;
	cout << " Minutes Parked: " << car.getMinParked() << endl;
}

Your code had alot of errors.. in fact, it would be a miracle for it to run in this state. First, you didn't need to write it in d Win32 way(what with your using TCHAR, _int,etc). U should have just done it the normal console way since it's not a Windows app. Second, in your ParkedCar class, you declared the member variablea as private and then tried to use public accessors and mutators on the. Like it'll ever work! To access them, put them as public also. Third, you put this line :

return 0;

right after this:

car.setMinParked(125);

If all was right, this program would never run. You're telling the system to exit after filling the member variables of Car! the couts would never execute.
This version of your code should help you out..

#ifndef	PARKEDCAR_H
#define PARKEDCAR_H
#include <iostream>
#include <string>
using namespace std;

class Parkedcar
{
public://Changed to public, so the unresolved externals were resolved. check PoliceOfficer for more details
	string make;	// Holds make of parked car
	string model;	// Holds model of parked car
	string color;	// Holds color of parked car
	string licNum;	// Holds license number of parked car
	int minParked;	// Holds minutes of parked car
public:
	Parkedcar(){
		cout<<"ParkedCar's ctor"<<endl;
	}
	// Constructor

	void setMake(string pcMake)
	{
		make = pcMake;
	}
	void setModel(string pcModel)
	{
		model = pcModel;
	}
	void setColor(string pcColor)
	{
		color = pcColor;
	}
	void setLicNum(string pcLicNum)
	{
		licNum = pcLicNum;
	}
	void setMinParked(int pcMin)
	{
		minParked = pcMin;
	}
	
	string getMake()
	{
		return make;
	}
	string getModel()
	{
		return model;
	}
	string getColor()
	{
		return color;
	}
	string getLicNum()
	{
		return licNum;
	}
	int getMinParked()
	{
		return minParked;
	}
	

};
#endif

#ifndef PARKINGMETER_H
#define PARKINGMETER_H
#include <string>
#include <iostream>
using namespace std;

class ParkingMeter
{
	private: 
		int minPurchased;
	public:
		
		ParkingMeter(int mPurchased)
		{
			minPurchased = mPurchased;
		}

		void setMinutesPurchased(int mPurchased)
		{
			minPurchased = mPurchased;
		}
		int getMinPurchased()
		{
			return minPurchased;
		}

		void print ()const
		{
			cout << " Minutes of parking time that has been purchased: " << endl;
		}
};
#endif

#ifndef	PARKINGTICKET_H
#define PARKINGTICKET_H
#include <iostream>
#include <string>
using namespace std;

class ParkingTicket
{
private://You kept making this mistake, check PoliceOfficer for more details
	string make;			// Holds make of parked car
	string model;			// Holds make of parked car
	string color;			// Holds make of parked car
	string licNum;			// Holds make of parked car
	string officerName;		// Holds name of police officer
	string badgeNum;		// Holds badge number of police officer
	int minParked;			// Holds time that car has been parked
	int minPurchased;		// Holds time purchased at parking meter
	int difference;			// Holds time 
public:
	ParkingTicket();
		
	void setMake(string ptMake)
	{
		make = ptMake;
	}
	void setModel(string ptModel)
	{
		model = ptModel;
	}
	void setColor(string ptColor)
	{
		color = ptColor;
	}
	void setLicNum(string ptLicNum)
	{
		licNum = ptLicNum;
	}
	void setOfficerName(string ptOffName)
	{
		officerName = ptOffName;
	}
	void setBadgeNum(string ptBadgeNum)
	{
		badgeNum = ptBadgeNum;
	}
	void setMinParked(int minPark)
	{
		minParked = minPark;
	}
	void setMinPurchased(int minPurchase)
	{
		minPurchased = minPurchase;
	}
	void setDifference(int diff)
	{
		difference = diff;
	}
	string getMake()
	{
		return make;
	}
	string getModel()
	{
		return model;
	}
	string getColor()
	{
		return color;
	}
	string getLicNum()
	{
		return licNum;
	}
	string getOfficerName()
	{
		return officerName;
	}
	string getBadgeNum()
	{
		return badgeNum;
	}
	int getMinParked()
	{
		return minParked;
	}
	int getMinPurchased()
	{
		return minPurchased;
	}
	int getDifference()
	{
		return difference;
	}
};
#endif

#ifndef	POLICEOFFICER_H
#define POLICEOFFICER_H
#include <iostream>
#include <string>
using namespace std;

class PoliceOfficer
{
private:
	string officerName;		// You declared them as private..
	string badgeNum;		
public:
	PoliceOfficer();

	void setOfficerName(string poOffName)
	{
		officerName = poOffName;//then tried to access them with public methods. 
		//If you declared a PoliceOfficer instance, then you would have gotten more unresolved externals!! 
	}
	void setBadgeNum(string poBadgeNum)
	{
		badgeNum = poBadgeNum;
	}
	string getOfficerName()
	{
		return officerName;
	}
	string getBadgeNum()
	{
		return badgeNum;
	}
};
#endif

#include <iostream>
#include <string>
#include<tchar.h>//no need for this
using namespace std;

int main()//This is the right way for console style programs..not the one you did
{
	
	// Create a Car object.
	Parkedcar car;
	car.setMake("Ford");
	car.setModel("Mustang");
	car.setColor("Purple");
	car.setLicNum("JKL123");
	car.setMinParked(125);
    //You put return 0 here: the statements below would never execute!!

	cout << " Make: " << car.getMake() << endl;
	cout << " Model: " << car.getModel() << endl;
	cout << " Color: " << car.getColor() << endl;
	cout << " License Number: " << car.getLicNum() << endl;
	cout << " Minutes Parked: " << car.getMinParked() << endl;
	return 0;
}

thanks a lot~I 've fixed a part of my code....but I don't understand how to access the members with public method for my PoliceOfficer...
can you give me more detail or example,please??

Do you mean access the data members of the class policeOfficer ?
You have to use the get/set methods defined in the class policeOfficer
In the main function you have used the get/ set methods in for the class Parked Car.... Use that for example

You can only use public methods to access public member variables. So remove all the privates and put them to public. You only use private when you dont wanna access them from public methods.

Please if this solved your problems, mark this thread as solved.

You can only use public methods to access public member variables. So remove all the privates and put them to public. You only use private when you dont wanna access them from public methods.

Please if this solved your problems, mark this thread as solved.

Incorrect...

The whole point of a public API is to allow external code/users controlled access to private and protected members.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

class demo {
private:
  int aPrvInt;

public:
  demo(int newInt = 0) { aPrvInt = newInt; }
  int getPrvInt() const { return aPrvInt; }
  void setPrvInt(int newInt) { aPrvInt = newInt; }
  void showIntDoubled() { cout << "aPrvInt doubled is: " << (aPrvInt *2) << endl; }
};

int main() {
  demo demoObj1, demoObj2(3);

  cout << "demoObj1::aPrvInt=" << demoObj1.getPrvInt() << endl;
  cout << "demoObj2::aPrvInt=" << demoObj2.getPrvInt() << endl << endl;
  demoObj1.setPrvInt(4);
  cout << "demoObj1::aPrvInt is now " << demoObj1.getPrvInt() << endl;
  cout << "demoObj1::";
  demoObj1.showIntDoubled();
  cout << endl;
  cout << "demoObj2::";
  demoObj2.showIntDoubled();
  cout << endl;
  cin.get();
  return 0;
}

Compile and run that. It should work.

Mistake there... What I'm trying to say is this; accessing private members this way

private:
int x=0;
//....

int main()
//assume obj is an instance of the class where x resides
obj.x=15;//wrong!!
return 0;
}

Thanks , Fbody for correcting me.

Mistake there... What I'm trying to say is this; accessing private members this way

private:
int x=0;
//....

int main()
//assume obj is an instance of the class where x resides
obj.x=15;//wrong!!
return 0;
}

Thanks , Fbody for correcting me.

OK. That makes more sense. I think that is generally referred to as "user" code, but please don't quote me on that. User code can not directly access private/protected members under normal circumstances, but I don't want to get into that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.