Hi,
One thing I would like to know you is, it is not part of my project or assignment. It is just a exercise from my text book.
Problem is I can't find a error in my code. Could someone help me???
If so, here is the question.
Implement a class PEmployee that is just like the Employee class except that it stores an object type Person as developed in the preceding exercise.
My code is
[code]
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
Person();
Person(string pname, int page);
void geta_name() const;
void geta_age() const;
private:
string name;
int age;
};
Person::Person()
{
}
Person::Person(string pname, int page)
{
name = pname;
age = page;
}
Whats the compiling problem? There isn't a "right way" to code, but there are better ways once you learn them. In other words, if the program works as required by the psuedocode or the problem parameters, then your fine.
One thing I would recommend is using ADT till you get a better grip on classes. Separating the implementation and the class declaration.
return type dont match:
p_data is Person type
this must be corrent:
string PEmployee::get_name() const
{
return p_data.get_name(); //I think that I am wrong here
} //I don't know how to fix it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
this is wrong,
if you declare here p_data, it will be local variable, not global
PEmployee::PEmployee(string e_name, double ini_salary)
{
Person p_data ("Min", 27);
}
that is why
use like this:
if you declare here p_data, it will be local variable, not global
PEmployee::PEmployee(string e_name, double ini_salary)
{
Person p_data_temp ("Min", 27);
p_data = p_data_temp;
}
1 2 3 4 5 6 7 8 9
u have to change geta_name(();
string Person::geta_name() const
{
cout << name;
return name;
}