HW Help

My program is to print out the student inputted Name, Age,Mailing Address using classes, struct and h files.

I'm getting an undeclared identifier for my privates.

*****This is my Student.h file.******

#ifndef STUDENT_H
#define STUDENT_H

#include <iostream>
#include <string>
using namespace std;

struct Address
{
string street, city, state, zip;
};
class Student{
private:
string name;
Address MailingAddress;
Address PhysicalAddress;
double age;
public:

Student();
Student(string name, Address MailingAddress,Address PhysicalAddress, double age);
~Student();

void setName(string iname);
void setMailingAddress(Address iMailingAddress);
void setPhysicalAddress(Address iPhysicalAddress);
void setAge(double iage);

string getName();
Address getMailingAddress();
Address getPhysicalAddress();
double getAge();
};

#endif

****This is my one of my cpp****

#include "Student.h"
#include <string>
//INITIALIZATION

Student::Student(string n,Address mA,Address pA,double a)
{
name = n;
MailingAddress = mA;
PhysicalAddress = pA;
age = a;
}
Student::~Student()
{
cout << "Instance removed from memory" << endl;
}

//SETTERS
void Student::setName(string name)
{name = name;}

void Student::setMailingAddress(Address MailingAddress)
{MailingAddress = MailingAddress;}

void Student::setPhysicalAddress(Address PhysicalAddress)
{PhysicalAddress = PhysicalAddress;}

void Student::setAge(double age)
{age = age;}
//GETTERS
string Student::getName()
{return name;}

Address Student::getMailingAddress()
{return MailingAddress;}

Address Student::getPhysicalAddress()
{return PhysicalAddress;}

double Student::getAge()
{return age;}

Last edited on
1
2
void Student::setName(string name)
{name = name;}

You need to assign the parameter to the class member, but they have the same name.

1. You can change the parameter name:
1
2
void Student::setName(string value)
{name = value;}


2. Or you can use "this" to disambiguate the symbol.
1
2
void Student::setName(string name)
{this->name = name;}

Topic archived. No new replies allowed.