So I'm writing a Manager class which inherits from SalariedEmployee which inherits from Employee. I have the employee.h header file and employee.cpp header file and also for salariedemployee as shown below.
I cant seem to understand why I get the following errors when I try to compile the code of
Undefined symbol: employeessavitch::SalariedEmployee::SalariedEmployee()
Undefined symbol: employeessavitch::SalariedEmployee::SalariedEmployee()
Undefined symbol: employeessavitch::SalariedEmployee::get_salary() const
Undefined symbol: employeessavitch::Employee::get_ssn() const
Undefined symbol: employeessavitch::Employee::get_name() const
Here are my files
employee.h
#ifndef employee_h
#define employee_h
#include <string>
#include "employee.h"
using namespace std;
namespace employeessavitch
{
class Employee
{
public:
Employee();
Employee(string the_name, string the_ssn);
string get_name( ) const;
string get_ssn( ) const;
double get_net_pay( ) const;
void set_name(string new_name);
void set_ssn(string new_ssn);
void set_net_pay(double new_net_pay);
void print_check( ) const;
protected:
string name;
string ssn;
double net_pay;
};
}
#endif /* employee_h */
employee.cpp
#include <string>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include "employee.h"
using namespace std;
namespace employeessavitch
{
Employee::Employee(): name("No name yet"), ssn("No number yet"), net_pay(0)
{
//deliberately empty
}
Employee::Employee(string the_name, string the_ssn)
{
//deliberately empty
}
Employee::Employee(string the_name, string the_number): name(the_name), ssn(the_number), net_pay(0)
{
//deliberately empty
}
string Employee::get_name() const
{
return name;
}
string Employee::get_ssn() const
{
return ssn;
}
double Employee::get_net_pay() const
{
return net_pay;
}
void Employee::set_name(string new_name)
{
name = new_name;
}
void Employee::set_ssn(string new_ssn)
{
ssn = new_ssn;
}
void Employee::set_net_pay (double new_net_pay)
{
net_pay = new_net_pay;
}
void Employee::print_check( ) const
{
cout << "\nERROR: print_check FUNCTION CALLED FOR AN \n"
<< "UNDIFFERENTIATED EMPLOYEE. Aborting the program.\n"
<< "Check with the author of the program about this bug.\n";
exit(1);
}
}//employeessavitch
salariedemployee.h
#ifndef salariedemployee_h
#define salariedemployee_h
#include <string>
#include "employee.h"
#include "salariedemployee.h"
namespace employeessavitch
{
class SalariedEmployee : public Employee
{
public:
SalariedEmployee();
SalariedEmployee (string the_name, string the_ssn, double the_weekly_salary);
double get_salary() const;
void set_salary(double new_salary);
void print_check();
protected:
double salary;//weekly
};
}//employeessavitch
#endif /* salariedemployee_h */
salariedemployee.cpp
#include <iostream>
#include <string>
#include <stdio.h>
#include "salariedemployee.h"
using namespace std;
namespace employeessavitch
{
SalariedEmployee::SalariedEmployee() //: Employee(), salary(0)
{
//deliberately empty
}
SalariedEmployee::SalariedEmployee(string the_name, string the_number, double the_weekly_salary)//: Employee(the_name, the_number), salary(the_weekly_salary)
{
//deliberately empty
}
double SalariedEmployee::get_salary() const
{
return salary;
}
void SalariedEmployee::set_salary(double new_salary)
{
salary = new_salary;
}
void SalariedEmployee::print_check()
{
set_net_pay(salary);
cout << "\n__________________________________________________\n";
cout << "Pay to the order of " << get_name( ) << endl;
cout << "The sum of " << get_net_pay( ) << " Dollars\n";
cout << "_________________________________________________\n";
cout << "Check Stub NOT NEGOTIABLE \n";
void SalariedEmployee::print_check()
{
set_net_pay(salary);
cout << "\n__________________________________________________\n";
cout << "Pay to the order of " << get_name( ) << endl;
cout << "The sum of " << get_net_pay( ) << " Dollars\n";
cout << "_________________________________________________\n";
cout << "Check Stub NOT NEGOTIABLE \n";
cout << "Employee Number: " << get_ssn( ) << endl;
cout << "Salaried Employee. Regular Pay: "
<< salary << endl;
cout << "_________________________________________________\n";
}
}//employeessavitch
main.cpp
#include <iostream>
#include <cstring>
#include <string>
#include <string.h>
#include <fstream>
#include "salariedemployee.h"
#include "employee.h"
using namespace std;
namespace employeessavitch
{
class Manager: public SalariedEmployee
{
public:
Manager();
~Manager();
void addReport(SalariedEmployee employee);
friend ostream& operator <<(ostream &outs, Manager manager);
private:
SalariedEmployee *reports;
int noReport;
};
Manager::Manager()
{
noReport = 0;
}
Manager::~Manager()
{
delete[] reports;
}
void Manager::addReport(SalariedEmployee employee)
{
SalariedEmployee *report = new SalariedEmployee[noReport+1];
for(int i = 0; i < noReport; i++)
{
report[i] = reports[i];
}
report[noReport+1] = employee;
delete[] reports;
}
ostream& operator <<(ostream &outs, Manager manager)
{
for(int i = 0; i < manager.noReport; i++)
{
outs << manager.reports[i].get_name() << endl;
outs << manager.reports[i].get_ssn() << endl;
outs << manager.reports[i].get_salary() << endl;
}
return outs;
}
}
int main()
{
cout << "hello world";
return 0;
}
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 months ago.
I'm new to this multi-file class stuff and I've got an undefined reference for both of my classes and I think it has something to do with my initialization and default constructor but honestly have no clue if any of this is correct at all. Any help is greatly appreciated.
main.cpp
#include "Artist.h"
#include "Artwork.h"
#include <iostream>
#include <string>
using namespace std;
int main() {
string userTitle, userArtistName;
int yearCreated, userBirthYear, userDeathYear;
getline(cin, userArtistName);
cin >> userBirthYear;
cin.ignore();
cin >> userDeathYear;
cin.ignore();
getline(cin, userTitle);
cin >> yearCreated;
cin.ignore();
Artist userArtist = Artist(userArtistName, userBirthYear, userDeathYear);
Artwork newArtwork = Artwork(userTitle, yearCreated, userArtist);
newArtwork.PrintInfo();
}
Artist.h
#ifndef ARTISTH
#define ARTISTH
#include <string>
using namespace std;
class Artist{
public:
Artist();
Artist(string artistName, int birthYear, int deathYear);
string GetName() const;
int GetBirthYear() const;
int GetDeathYear() const;
void PrintInfo() const;
private:
string artistName;
int birthYear;
int deathYear;
};
#endif
Artist.cpp
#include "Artist.h"
#include <iostream>
#include <string>
using namespace std;
Artist::Artist()
{
artistName = "unknown";
birthYear = -1;
deathYear = -1;
}
string Artist::GetName() const
{
return artistName;
}
int Artist::GetBirthYear() const
{
return birthYear;
}
int Artist::GetDeathYear() const
{
return deathYear;
}
void Artist::PrintInfo() const
{
if(deathYear > 0 && birthYear > 0)
{
cout << "Artist: " << artistName <<" ("<< birthYear << " to "<< deathYear << ")" <<
endl;
}
else if(birthYear > 0 && deathYear < 0)
{
cout << "Artist: " << artistName <<" ("<< birthYear << " to present)" << endl;
}
else if(birthYear<0 && deathYear<0)
{
cout << "Artist: " << artistName << " (unknown)" << endl;
}
}
Artwork.h
#ifndef ARTWORKH
#define ARTWORKH
#include "Artist.h"
class Artwork{
public:
Artwork();
Artwork(string title, int yearCreated, Artist artist);
string GetTitle();
int GetYearCreated();
void PrintInfo();
private:
string title;
int yearCreated;
Artist artist;
};
#endif
Artwork.cpp
#include "Artwork.h"
#include <iostream>
Artwork::Artwork()
{
cout <<"Artwork has started." << endl;
title = "unknown";
yearCreated = -1;
Artist artist(); //here im not sure how to initialize an object inside of an object
}
string Artwork::GetTitle()
{
return title;
}
int Artwork::GetYearCreated()
{
return yearCreated;
}
void Artwork::PrintInfo()
{
artist.PrintInfo();
cout << "Title: " << title << ", " << yearCreated << endl;
}
I was correct, i needed to initialize both a default(no input parameters) constructor and a constructor with input parameters.
to correctly write a default and parameter constructor, do this
Artwork::Artwork(string n, int y, Artist a)
{
title = n;
yearCreated = y;
artist = a;
}//constructor with given input
Artwork::Artwork()
{
title = "unknown";
yearCreated = -1;
}//if input is not given for any fields, refer to this constructor
Notice that the default constructor does not have an object, I'm honestly not sure if there is a way to initialize a blank object and if so, why that isn't necessary.
The Artist constructor looks the same,
Artist::Artist(string name, int birth, int death)
{
artistName = name;
birthYear = birth;
deathYear = death;
}
Artist::Artist()
{
artistName = "unknown";
birthYear = -1;
deathYear = -1;
}
I didn't include a Player.h file or .cpp file since they're exactly the same as my Monster.h and .cpp file.
I'm making a game and I created a player object in my Login.cpp file that takes the username and an int as the parameters. Is there a way to access the object's parameters in my BattleStats() function within my BattleSystem.cpp file? My goal is to eventually update the parameters as the player gets hit by the monster and to output those updated parameters.
Here's my code, thank you for the help:
Main.cpp
#include "Login.h"
#include "GameManager.h"
#include "BattleSystem.h"
#include <iostream>
using namespace std;
int main() {
BattleSystem bs;
GameManager gm(&bs);
Login login(&gm);
login.StartMenu();
cout << "ENDING" << endl;
system("pause"); //Pause console.
return 0; //Terminated without errors.
}
Login.h
#pragma once
#include "GameManager.h"
#include <iostream>
using namespace std;
class Player;
class GameManager;
class Login {
public:
Login(GameManager* gmPtr) : manager(gmPtr) {}
void StartMenu();
private:
string username = "Kujo";
Player* player;
GameManager* manager;
};
Login.cpp
#include "Login.h"
#include "Player.h"
#include "GameManager.h"
void Login::StartMenu() {
player = new Player(username, 100);
manager->GameStart();
}
GameManager.h
#pragma once
class BattleSystem;
class GameManager {
public:
GameManager(BattleSystem* bsPtr) : battle(bsPtr) {}
void GameScenario();
private:
int level = 1;
BattleSystem* battle;
};
GameManager.cpp
#include "BattleSystem.h"
#include "Login.h"
#include "GameManager.h"
void GameManager::GameScenario() {
battle->Encounter();
}
BattleSystem.h
#pragma once
class Player;
class Monster;
class BattleSystem {
public:
void Encounter();
void BattleStats();
private:
Monster* monster;
Player* player;
};
BattleSystem.cpp
#include "Player.h"
#include "Monster.h"
#include "BattleSystem.h"
void BattleSystem::Encounter() {
monster = new Monster("Mini Orc", 100);
cout << "A " << monster->GetName() << " has appeared!" << endl;
BattleStats();
}
void BattleSystem::BattleStats() {
cout << "Monster name: " << monster->GetName() << endl;
cout << "Monster HP: " << monster->GetHP() << endl << endl;
cout << "Player name: " << "PLAYER NAME HERE" << endl;
cout << "Player HP: " << "PLAYER HP HERE" << endl << endl;
}
Monster.h
#pragma once
#include <string>
#include <iostream>
using namespace std;
class Monster {
public:
Monster();
Monster(string monsterName, int health);
void SetName(string monsterName);
void SetHP(int health);
string GetName() const;
int GetHP() const;
private:
string name = "Monster";
int healthPoints = 0;
};
Monster.cpp
#include "Monster.h"
Monster::Monster() : name("Player"), healthPoints(0) {}
Monster::Monster(string monsterName, int health) {
name = monsterName;
healthPoints = health;
}
void Monster::SetName(string monsterName) {
name = monsterName;
}
void Monster::SetHP(int health) {
healthPoints = health;
}
string Monster::GetName() const {
return name;
}
int Monster::GetHP() const {
return healthPoints;
}
Try to insert friend BattleSystem to your Player class.
Then you will have an access to private fields of Player from BattleSystem.
When I compile the below code, for some reason, the student/instructors name, age, and GPA/Rating, are not returned via their respective printPerson functions.
With the name variable, nothing is printed to the console.
With the age, GPA/Rating, console prints out a negative 8 digit number, and a negative float.
What am I not seeing?
Person.h
#pragma once
#ifndef PERSON_H
#define PERSON_H
#include <iostream>
#include <vector>
#include <string>
using std::string;
// Base class
class Person {
protected:
string name;
int age;
public:
void setName(string name);
void setAge(int age);
virtual void do_work(int number) {};
virtual void printPerson() {};
};
#endif;
Person.cpp
#include "Person.h"
#include <iostream>
#include <vector>
#include <string>
using std::cout;
using std::cin;
using std::endl;
void Person::setName(string name) {
name = name;
}
void Person::setAge(int age) {
age = age;
}
Student.h
#pragma once
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <vector>
#include <string>
#include "Person.h"
using std::string;
class Student : public Person {
private:
float gpa;
public:
void setGPA(float gpa);
float getGPA();
void do_work(int number);
void printPerson();
};
#endif;
Student.cpp
#include "Student.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
void Student::setGPA(float gpa) {
gpa = gpa;
}
float Student::getGPA() {
return gpa;
}
void Student::do_work(int number) {
//cout << name << ".. " << number << "hours of homework.” << endl;
cout << name;
}
void Student::printPerson() {
cout << "Name : " << name << "Age :" << age << " GPA : " << getGPA() << endl;
}
Instructor.h
#pragma once
#ifndef INSTRUCTOR_H
#define INSTRUCTOR_H
#include <iostream>
#include <vector>
#include <string>
#include "Person.h"
class Instructor : public Person {
private:
float rating;
public:
void setRating(float rating);
float getRating();
void do_work(int number);
void printPerson();
};
#endif;
Instructor.cpp
#include "Instructor.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
void Instructor::setRating(float rating) {
rating = rating;
}
float Instructor::getRating() {
return rating;
}
void Instructor::do_work(int number) {
cout << name << "graded papers for" << number << "hours." << endl;
}
void Instructor::printPerson() {
cout << " Name : " << name << " Age : " << age << " Rating : " << getRating() << endl;
}
University.h
#pragma once
#ifndef UNIVERSITY_H
#define UNIVERSITY_H
#include <iostream>
#include <vector>
#include <string>
#include "Person.h"
#include "Building.h"
#include "Student.h"
using std::cout;
using std::string;
using std::vector;
class University {
public:
string name;
vector<Person*> persons;
vector<Building> buildings;
public:
void printAllBuildings();
void printAllPersonsRecord();
};
#endif;
University.cpp
#include "University.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
void University::printAllBuildings() {
cout << " Building Details : " << endl;
for (int j = 0; j < buildings.size(); j++) {
buildings[j].printBuilding();
}
}
void University::printAllPersonsRecord() {
cout << " Persons Details : " << endl;
for (int i = 0; i < persons.size(); i++) {
persons[i]->printPerson();
}
}
Building.h
#pragma once
#ifndef BUILDING_H
#define BUILDING_H
#include <iostream>
#include <vector>
#include <string>
#include "Person.h"
class Building {
public:
string name;
int size;
string address;
public:
void printBuilding();
};
#endif;
Building.cpp
#include "Building.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
void Building::printBuilding() {
cout << " Name : " << name << " Address : " << address << endl;
}
main.cpp
#include "University.h"
#include "Person.h"
#include "Student.h"
#include "Instructor.h"
#include <iostream>
#include <vector>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
int main() {
Student student;
Instructor instructor;
student.setName("deepak");
student.setAge(12);
student.setGPA(12.0);
instructor.setName("rajdev");
instructor.setAge(23);
instructor.setRating(5.0);
Building building;
building.name = "block1";
building.size = 2000;
building.address = "noida sector-2";
Building building2;
building2.name = "block2";
building2.size = 4000;
building2.address = "noida sector-2";
University university;
university.name = "Oregon State University";
university.persons.emplace_back(&student);
university.persons.emplace_back(&instructor);
university.buildings.push_back(building);
university.buildings.push_back(building2);
university.printAllBuildings();
university.printAllPersonsRecord();
int choice;
bool isValidMainChoice = false;
while (!isValidMainChoice) {
cout << "Kindly choose one of the option from follwoing list of operations or Menu" << endl;
cout << "1 : Prints names of all the buildings" << endl;
cout << "2 : Prints names of everybody at the university" << endl;
cout << "3 : Choose a person to do work" << endl;
cout << "4 : Exit the program" << endl;
cin >> choice;
cout << "The value you entered is " << choice << endl;
if (choice == 1) {
university.printAllBuildings();
}
else if (choice == 2) {
university.printAllPersonsRecord();
}
else if (choice == 3) {
int personChoice;
bool isInputValid = false;
while (!isInputValid) {
cout << "Kindly choose the one of the following option to provide person's details." << endl;
cout << "5 : Student" << endl;
cout << "6 : Instructor" << endl;
cin >> personChoice;
if (personChoice == 5) {
isInputValid = true;
string studentName;
bool isValidName = false;
while (!isValidName) {
cout << " Kindly enter Name of the student :" << endl;
cin >> studentName;
if (studentName.length() == 0) {
cout << " Name must not be blank. Kindly re-enter the student's name." << endl;
}
else {
isValidName = true;
}
}
int age1 = 0;
bool isValidAge1 = false;
while (!isValidAge1) {
cout << " Kindly enter age of the student :" << endl;
cin >> age1;
if (age1 < 0 || age1 > 100) {
cout << " Age must be geter than 0 or lessa then 100. Kindly re-enter the student's age." << endl;
}
else {
isValidAge1 = true;
}
}
float gpa;
bool isValidGPA = false;
while (!isValidGPA) {
cout << " Kindly enter GPA of the student :" << endl;
cin >> gpa;
if (gpa < 0.0 || gpa > 4.0) {
cout << " GPA must be geter than 0.0 or less then 4.0. Kindly re-enter the Student GPA." << endl;
isValidGPA = false;
}
else {
isValidGPA = true;
}
}
Student student;
student.setName(studentName);
student.setAge(age1);
student.setGPA(gpa);
university.persons.emplace_back(&student);
university.printAllPersonsRecord();
}
else if (personChoice == 6) {
isInputValid = true;
string instructorName;
bool isValidName = false;
while (!isValidName) {
cout << " Kindly enter Name of the instructor :" << endl;
cin >> instructorName;
if (instructorName.length() == 0) {
cout << " Name must not be blank. Kindly re-enter the instructor's name." << endl;
}
else {
isValidName = true;
}
}
float rating;
bool isValidRating = false;
while (!isValidRating) {
cout << " Kindly enter rating of the instructor :" << endl;
cin >> rating;
if (rating < 0.0 || rating > 5.5) {
cout << " rating must be geter than 0.0 or less then 5.5. Kindly re-enter the instructor rating." << endl;
isValidRating = false;
}
else {
isValidRating = true;
}
}
int age2 = 0;
bool isValidAge2 = false;
while (!isValidAge2) {
cout << " Kindly enter age of the instructor :" << endl;
cin >> age2;
if (age2 < 0 || age2 > 100) {
cout << " Age must be geter than 0 or lessa then 100. Kindly re-enter the instructor's age." << endl;
}
else {
isValidAge2 = true;
}
}
Instructor instructor;
instructor.setName(instructorName);
instructor.setAge(age2);
instructor.setRating(rating);
university.persons.emplace_back(&instructor);
}
else {
cout << "The value you entered is incorrct.Please r-enter the values." << endl;
}
}
}
else if (choice == 4) {
isValidMainChoice = true;
cout << " You are exits from system. Thanks You !!" << endl;
}
}
return 0;
};
Please modify all your code for setter
void Person::setName(string name) {
//before-edit: name = name;
this->name = name; //OR Person::name = name;
}
As the local string name parameter and your class variable are the same, you expect the parameter are passed correctly, but it doesn't.
got a quick question. Why does the first programm work, but not the one when i split it into header/source file? How can i fix this? (error is that there is no default-constructor for "Stud s [line 6 main.cpp]")
Here is my code:
The working one:
#include <iostream>
#include <string>
using namespace std;
class Stud {
private:
string pren, surn;
unsigned int number;
public:
Stud(string p = "", string s = "", unsigned int n = 0) : pren(p), surn(s), number(n)
{
return;
}
friend ostream& operator<<(ostream& os, Stud& st) {
os << st.number << ", " << st.pren << " " << st.surn;
return os;
}
};
int main() {
Stud s;
Stud test("x", "y", 123);
cout << s << endl;
cout << test << endl;
}
Now the splitted one:
stud.hpp:
#ifndef STUD_HPP
#define STUD_HPP
#include <iostream>
#include <string>
class Stud {
private:
std::string pren, surn;
unsigned int number;
public:
Stud(std::string, std::string, unsigned int);
friend std::ostream& operator<<(std::ostream&, const Stud&);
};
#endif
stud.cpp:
#include "stud.hpp"
Stud::Stud(std::string p = "", std::string s = "", unsigned int n = 0) : pren(p), surn(s), number(n)
{
return;
}
std::ostream& operator<<(std::ostream& os, const Stud& st) {
os << st.number << ", " << st.pren << " " << st.surn;
return os;
}
main.cpp
#include <iostream>
#include "stud.hpp"
using namespace std;
int main() {
Stud s;
Stud test("x", "y", 123);
cout << s << endl;
cout << test << endl;
}
I am trying to test my code for a few classes that I have created, but I'm running into some difficulties in trying to compile. I have three class and a main class. The first class is a person class and the second and third are student and faculty which is derived from person.
Here is what I have for the Person.h class:
#ifndef Person_H
#define Person_H
#include <string>
using namespace std;
class Person
{
protected:
long id;
string name;
string email;
string address;
string dateOfBirth;
string gender;
public:
Person(long pId);
Person(long pId, string pName, string pEmail, string pAddress, string pDateOfBirth, string pGender);
void print() const;
};
#endif
Here is my Person.C
#include <iostream>
#include "Person.h"
using namespace std;
Person::Person(long pId)
{
id = pId;
name = "Nothing";
email = "Nothing";
address = "Nothing";
dateOfBirth = "Nothing";
gender = "Nothing";
}
Person::Person(long pId, string pName, string pEmail, string pAddress, string pDateOfBirth, string pGender)
{
id = pId;
name = pName;
email = pEmail;
address = pAddress;
dateOfBirth = pDateOfBirth;
gender = pGender;
}
void Person::print() const
{
cout << "ID: " << id << endl;
cout << "Name: " << name << endl;
cout << "Email: " << email << endl;
cout << "Address: " << address << endl;
cout << "Date of Birth: " << dateOfBirth << endl;
cout << "Gender: " << gender << endl;
}
here is the Student.h
#ifndef Student_H
#define Student_H
#include<string>
#include <vector>
#include "Person.h"
#include "Course.h"
using namespace std;
class Student:public Person
{
protected:
int yearOfStudy;
string major;
long advisorId;
vector <Course> coursesTaken;
static long nextStId;
public:
Student();
Student(string sName, string sEmail, string sAddress, string sDateOfBirth, string sG\
ender, int sYearOfStudy, string sMajor, long sAdvistorId);
void print() const;
};
#endif
Here is the Student.C
#include<iostream>
#include "Student.h"
using namespace std;
long Student::nextStId = 500;
Student::Student():Person(nextStId)
{
yearOfStudy = 0;
major = " ";
advisorId = 0;
}
Student::Student(string sName, string sEmail, string sAddress, string sDateOfBirth, st\
ring sGender, int sYearOfStudy, string sMajor, long sAdvisorId):Person(nextStId, sName\
, sEmail, sAddress,sDateOfBirth, sGender)
{
yearOfStudy = sYearOfStudy;
major = sMajor;
advisorId = sAdvisorId;
}
void Student::print() const
{
Person::print();
cout << "Year of study: " << yearOfStudy << endl;
cout << "Major: " << major << endl;
cout << "Advisor ID: " << advisorId << endl;
}
Now in my main, I have:
#include <iostream>
#include <string>
#include "Faculty.h"
#include "Student.h"
#include "Person.h"
using namespace std;
int main()
{
Student test1;
Faculty test2;
test1.print();
cout << endl;
test2.print();
return 0;
}
The error that I receive when I try to compile is:
g++ Assignment3.C Person.C Student.C Faculty.C
Assignment3.C: In function âint main()â:
Assignment3.C:10: error: âStudentâ was not declared in this scope
Assignment3.C:10: error: expected `;' before âtest1â
Assignment3.C:12: error: âtest1â was not declared in this scope
I don't understand why it's giving me that error. My faculty class seems to running perfectly fine. Could someone help please!
I'm not specialist, but don't you need have () after test1? Like Student test1 (); I know it's not related to the error, but you can check.