classes

lass Person
{
public:
Person( string, string, int );
void setFirstName( string );
string getFirstName();
void setLastName( string );
string getLastName();
void setAge( int );
int getAge();
private:
string firstName;
string lastName;
int age;
}; // end class Person



// Person.cpp
// Creates and manipulates a person with a first name, last name and age
#include "Person.h"

Person::Person( string first, string last, int years )
{
setFirstName(first);
setLastName(last);
if ( years < 0 )
setAge(years) ;
} // end Person constructor

void Person::setFirstName( string first )
{
firstName = first;
} // end function setFirstName

string Person::getFirstName()
{
return firstName;
} // end function getFirstName

void Person::setLastName( string last )
{
lastName = last;
} // end function setLastName

string Person::getLastName()
{
return lastName;
} // end function getLastName

void Person::setAge( int years )
{
if ( years > 0 )
age = years;
} // end function setAge

int Person::getAge()
{
return years;
} // end function getAge



#include <iostream>
using namespace std;

#include "Person.h"

int main()
{
Person person("John", "Smith", 19);


cout << "Created " <<person.getFirstName() << " " << person.getLastName() << ", age "
<<person.getAge() << endl;

person.getAge() = person.getAge() + 1;
cout << "Happy Birthday to " << person.getFirstName() << " "
<< person.getLastName() << endl;
} // end main


i get these error("1value required as left operand of assignment") when ever i build this program
use setAge() to set the age:

person.getAge() = person.getAge() + 1; -> person.setAge(person.getAge() + 1);
Topic archived. No new replies allowed.