J
Hallo,
ich hatte einfach einen Denkfehler. So ist es richtig:
#include <iostream>
#include <string>
using namespace std;
class A{
private:
string name;
public:
A(string n="NN"):name(n){}
string getname1(void){return this->name;}
};
class B{
private:
string ort;
int plz;
A * aP;
public:
B(string o="NN",int p=00000):ort(o),plz(p),aP(new A){}//Konstruktor
B(string o,int p,string n):ort(o),plz(p),aP(new A(n)){}
B(const B & org):ort(org.ort),plz(org.plz),aP(new A(*org.aP)){}//Kopier Konstruktor
~B(){delete this->aP;}
string getname2(void){return this->aP->getname1();}
};
void main(void){
B b1("Hamburg",51119,"Peter");
cout <<"name von A von B b1: ";
cout << b1.getname2();
cin.ignore();
}
Mein Methode getname1 ist in A public und somit kann ich diese einfach in der Klasse B benutzen. Danke für die Antwort.