I want to use a conditional statement to create the objects of my 2 derived class depending on the user's input and i got some error. I turned off linker.
STUDENT* s2 = NULL;
string option;
cin >> option;
if (option == "PART-TIME")
{
s2 = new PartTime;
}
else if (option == "FULLTIME")
{
s2 = new FullTime;
}
1>------ Build started: Project: Pp2 project2, Configuration: Debug Win32 ------
1>Source.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification
1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall PartTime::PartTime(void)" (??0PartTime@@QAE@XZ) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall FullTime::FullTime(void)" (??0FullTime@@QAE@XZ) referenced in function _main
1>c:\users\johnson\documents\visual studio 2013\Projects\Pp2 project2\Debug\Pp2 project2.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It seems the linker couldn't find your PartTime and FullTime default constructor. Didn't you create one or did you forget to add the file to the project?
I'm a lil afraid to post up my code...since i'll get laugh at. But I'm in need of help so..here's the code. Not entirely sure if there's any other error, but for now, i want to be able to create objects through a condition statement. Feel free to point out my mistakes. Still learning.
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
you might wonder why the derive class looks so similar.. well the idea is that user to select either part time or full time since their credit hours are different. So whichever one the user select will do the work. So if they select part time, then part time object will be created and the full time class will just sit there. There's a lot of stuff i erased becuz i was trying to get the last part of the program working...so i erase there and there to try find out the reason. I'll have to restore them bk to how it was..the derive class and others.
As I guessed. Your PartTime and Fulltime constructors are missing + the STUDENT destructor.
You declared PartTime and Fulltime constructors but don't implement them.
yup, i changed all mines and added the {} empty body
There's actually no need to do that. You can just remove the declarations for those default constructors, if the bodies are empty. The compiler will create them for you.
The problem was because, as Thomas said, you declared them, but didn't implement them. Do neither, or do both.