Expression can not be evaluated

having some trouble with printing name out to file any thoughts

Person.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef H_Person
#define H_Person

#include <string>

using namespace std;

class Person
{
public:
	//Function to output the first name and last name
	//in the form firstName lastName
	void print() const;

	//Function to set firstNAme and lastName according to the parameters
	//Postcondition: firstName = first; lastName = last;
	void setName (string first, string last);

	//Function to return firstName
	//Postcondition: The value of firstName is returned.
	string getFirstName() const;

	//Function to return lastName
	//Postcondition: The value of lastName is returned.
	string getLastName() const;

	//Constructor
	//Sets firstName and lastName according to parameters
	//The default value of the parameters are null string.
	//Postcondition: firstName = first; lastName = last;
	Person(string first = " ", string last = " ");

private:
	//Variable to store the first name
	string firstName;

	//Variable to store last name
	string lastName;
};
#endif  


Person.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include "Person.h"

#include <string>

using namespace std;

void Person::print() const
{
	cout << firstName << " " << lastName;
}

void Person::setName(string first, string last)
{
	firstName = first;
	lastName = last;
}

string Person::getFirstName() const
{
	return firstName;
}

string Person::getLastName() const
{
	return lastName;
}

Person::Person(string first, string last)
{
	firstName = first;
	lastName = last;
}



Employee.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef H_Employee
#define H_Employee

#include <fstream>
#include <string>
#include "Person.h"

using namespace std;

class Employee: public Person
{
public:

	//Function to set Employee name.
	void setInfo(string fName, string lName);

	//Function to print the Employee name
	void print(ostream& outF);

	//Default constructor
	Employee();


private:
	
};
#endif 



Employee.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include "Person.h"
#include "Employee.h"

using namespace std;


void Employee::setInfo(string fName, string lName)
{
	//set name
	setName(fName, lName);	
}

Employee::Employee()
{

}
void Employee::print(ostream &outF)
{
	outF << "Employee Name: " << getFirstName() << " " << getLastName() << endl;
 
	outF << "**********************************************" << endl;
	cout << endl;

}


Main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <fstream>
#include <string>
#include "Employee.h"

using namespace std;

const int MAX_NO_OF_EMPLOYEES = 10;

void getEmployeeData(ifstream& infile, Employee employeeList[], int numberOFEmployees);

void printEmployeeReport(ofstream& outfile, Employee employeeList[], int numberOFEmployees);

int main()
{
	Employee employeeList[MAX_NO_OF_EMPLOYEES];

	int noOFEmployees;
    
	ifstream infile;
	ofstream outfile;
	
	infile.open("Data.txt");

	if(!infile)
	{
		cout << "The input file does not exist. " << "Program terminates. " << endl;
		return 1;
	}

	outfile.open("DataOut.txt");

	//get number of employees 
	infile >> noOFEmployees;

	getEmployeeData(infile, employeeList, noOFEmployees);

    printEmployeeReport(outfile, employeeList, noOFEmployees);

	return 0;
}

void getEmployeeData(ifstream& infile, Employee employeeList[], int numberOFEmployees)
{
	//local variables

	//loop control variable
	int count;

	//Variable to store the first name
	string fName;

	//Variable to hold last name
	string lName;

	for(count = 0; count < numberOFEmployees; count++)

			infile >> fName >> lName ;
	
	employeeList[count].setInfo(fName, lName);
}

void printEmployeeReport(ofstream& outfile, Employee employeeList[], int numberOFEmployees)
{
	int count;
	
	for(count = 0; count < numberOFEmployees; count++)

		employeeList[count].print(outfile);
}



Data.txt file

4
Johnathan Witvoet
Lorita Witvoet
Charles Dees
Kathalene Dees


did break point at line 23 in Employee.cpp and get CXX0030: Error: expression cannot be evaluated. looked this error up and it said: You may want to rewrite your expression using parentheses to control the order of evaluation. I stil do not under stand why? any help would be appreciated.

I don't see a problem but...try using this instead of implying it:

outF << "Employee Name: " << this->getFirstName() << " " << this->getLastName() << endl;
Topic archived. No new replies allowed.