Tworzenie obiektów w klasach

0

Cześć, powie mi ktoś dlaczego nie mogę utworzyć nowego obiektu dla klasy TOsoba?

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;
/*************************************************************************/
class adres///:public TOsoba
{
     string miasto;
     string ulica;
     int numer;
 public:
    adres(string, string , int);
    void Wyswietl();

};
    adres::adres(string miasto,string ulica,int numer)
    {
        this->miasto=miasto;
        this->ulica=ulica;
        this->numer=numer;
    }
    void adres:: Wyswietl()
    {
        cout<<"miasto: "<<miasto<<"\nulica: "<<ulica<<"\nnr: "<<numer;
    }
/************************************************************************************/
class TOsoba
{
    protected:
    string imie;
    string nazwisko;
    int wiek;
    //adres xx;
    public:
    TOsoba(string,string,int);//,adres
    void Wyswietl();
    string PodajImie();
  //  string PodajNazwisko( return nazwisko;)
};

TOsoba::TOsoba(string i,string n, int w)//,adres x
   {
        this->imie=i;
        this->nazwisko=n;
        this->wiek=w;
        //this->xx=x;

    }

    void TOsoba::Wyswietl()
    {
        cout<<"Imie: "<<imie<<"\nNazwisko: "<<nazwisko<<"\nWiek: "<<wiek;
    }
    string TOsoba::PodajImie()
    {
        return imie;
    }
/*************************************************************************************/


main()
{
    //adres a(Lubli,Kunickiego,22);
   TOsoba (Jan,Kowalski,21)
    //os1.PodajImie();
    os1.Wyswietl();
    return 0;
}
0

W C++ literały stringowe umieszcza się pomiędzy "".

BTW:

class adres///:public TOsoba

Adres jest osobą?

0

Adres ma być obiektem niezależnej klasy o polach: miasto, ulica, numer z konstruktorem ustawiajcym
pola na podstawie parametrów, destruktorem oraz metodą Wyświetl.

1

A może by tak TOsoba ("Jan","Kowalski",21)?

EDIT: A właściwie to:
TOsoba osoba = TOsoba("Jan", "Kowalski", 21);

0

Macie może jakiś pomysł jak przypisać adres do osoby i go wyświetlić? Mi ciągle wyskakuje błąd

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;
/*************************************************************************/
class adres//:public TOsoba
{
    protected:
     string miasto;
     string ulica;
     int numer;
 public:
    adres(string, string , int);
    void Wyswietl();

};
    adres::adres(string miasto,string ulica,int numer)
    {
        this->miasto=miasto;
        this->ulica=ulica;
        this->numer=numer;
    }
    void adres:: Wyswietl()
    {
        cout<<"miasto: "<<miasto<<"\nulica: "<<ulica<<"\nnr: "<<numer;
    }
/************************************************************************************/
class TOsoba
{
    protected:
    string imie;
    string nazwisko;
    int wiek;
    adres xx;
    public:
    TOsoba(string,string,int,adres);//,adres
    void Wyswietl();
    string PodajImie();
    string PodajNazwisko();
};

TOsoba::TOsoba(string i,string n, int w,adres x)//,adres x
   {
        this->imie=i;
        this->nazwisko=n;
        this->wiek=w;
        this->xx=x;

    }

    void TOsoba::Wyswietl()
    {
        cout<<"Imie: "<<imie<<"\nNazwisko: "<<nazwisko<<"\nWiek: "<<wiek<<"\nAdres: ";//<<adres::Wyswietl();
        adres::Wyswietl();
    }
    string TOsoba::PodajImie()
    {
        return imie;
    }
    string TOsoba::PodajNazwisko()
     {
         return nazwisko;
     }
/*************************************************************************************/
class TStudent: public TOsoba
{
    string kierunek;
    int rok;
public:
    TStudent(string,int);
    void Wyswietl();
    string PodajKierunek();
};
TStudent::TStudent(string k,int r)
{
    this->kierunek=k;
    this->rok=r;
}
void TStudent::Wyswietl()
{
    cout<<"Kierunek: "<<kierunek<<"\nRok: "<<rok;
}
/********************************************************************************************/
main()
{
    adres a("Lublin","Kunickiego",22);
   TOsoba os1("Jan","Kowalski",21,a);
   a.Wyswietl();
   TStudent st("Informatyka",1);
   st.Wyswietl();
    //os1.PodajImie();
    cout<<os1.PodajImie()<<endl;
    os1.Wyswietl();
    return 0;
}

1

W konstruktorze: this.xx = adres(x).

0

Zapisałem to trochę inaczej:

TOsoba::TOsoba(string i,string n, int w,adres x):xx(x)
   {
        this->imie=i;
        this->nazwisko=n;
        this->wiek=w;
        this->xx = adres(x);

    }

Dlaczego po dodaniu destruktorów do klasy adres i TOsoba wywala mi błędy? Jeśli w klasach utworze destruktory do adres i TOsoba to wtedy składniki klasy powinny być na wskaznikach " * "?

2
  1. Dlaczego nie:
TOsoba::TOsoba(string i,string n, int w,adres x)
    : xx(x)
    , imie(i)
    , nazwisko(n)
    , wiek(w)
{}
  1. Dlaczego nazwy masz takie pomieszane? Zdecyduj się na jakąś konwencję, bo ciężko czytać nawet tak krótki kod.
    a) co znaczy xx?
    b) dlaczego typy oznaczasz raz TOsoba (typ z dużej litery i z przedrostkiem T), a raz adres (typ z małej litery).

  2. Jak TStudent inicjuje klasę bazową TOsoba, bo jakoś nie widzę tego w kodzie?