In the following program:
#include <iostream>
#include <string>
using namespace std;
class Employee
{
private:
char name[20];
public:
Employee() {strcpy(name, "(no name)");}
Employee(char *n) {strcpy(name, n); }
void show() { cout << "Name" << name << endl; }
~Employee() { cout << "Employee destructor \n"; }
};
class Exempt : public Employee
{
private:
float salary;
public:
Exempt() { salary = 10000.0; }
Exempt(char *n, float s) : Employee(n)
{
salary = s;
}
void show()
{
Employee::show();
cout << "Salary " << salary << endl;
}
~Exempt()
{ cout << "Exempt destructor\n"; }
};
int main()
{
Employee e1("jackson"), *p1, *p2;
Exempt staff1;
Exempt x1("Alexander", 30000.0), *px = &x1;
Employee e2 = e1;
p1 = &e2;
p2 = &x1;
e1.show();
staff1.show();
(*p1).show();
p2 -> show(); // statement in question
px -> show();
}
in main, with the statement p2 ->show(); how is the output Name Alexander?
when you are sending addresses can you by pass the arguements? i really am confused on this, i dont understand how Name Alexander would be printed.