Jako raczkujący adept obj. c++, wychodzę z takim zapytaniem
mam dwie klasy:
Adres.h
class Address {
std::string street;
std::string apt;
public:
Address(std::string s, std::string a);
void showAddress() const;
void setStreet(std::string s);
void setApt(std::string a);
virtual ~Address();
};
oraz Student.h
class Student {
std::string name;
std::string surname;
const std::string PESEL;
Address *residentialAddress;
Address *permanentAddress;
public:
Student();
Student(std::string n, std::string s, std::string p);
void showInfo() const;
void setResidentialAddress(Address & rA);
void setPermanentAddress(Address & pA);
virtual ~Student();
};
w main.cpp
Address address("Morawskiego", "16");
Student* nobody = new Student();
nobody->setPermanentAddress(&address);
cout<<nobody->showInfo()<< endl;
Chciałbym wywołując metodę setPermanentAddress do której przekazuję obiekt address przez referencję, ustawić wartości pól permanentAddress na zgodne z wartościami pól obiektu address . Natomiast nie za bardzo wiem jak tego dokonać. Napisałem taką metodę w klasie Student, natomiast jak szybko się okazało, daleko na tym nie zajechałem.
void Student::setPermanentAddress(Address & rA) {
permanentAddress->setApt(rA.apt);
permanentAddress->setStreet(rA.street);
}
Będę wdzięczny za wszelką pomoc w tym problemie, gdyż nie mogę doszukać się błędu. Pozdrawiam