Quantcast
Channel: Forum Pasja Informatyki - Najnowsze pytania bez odpowiedzi
Viewing all articles
Browse latest Browse all 21942

Przykład z "Pasji"szablon klas - Przykład programu z książki nie chce się skompilować.

$
0
0

Witam

nie moge skompilować przykładu z książki "Pasja".Program uruchamia się ale zawiesza.Coś nie tak jest z klasą wektor ale nie wiem co....Prosze o pomoc

 

 

#include <iostream>
#include<string.h>
using namespace std;
class osoba{
char nazwisko[30];
public:
    osoba(char*n=NULL)
    {
        strcpy(nazwisko,n);
    }
    friend ostream&operator<<(ostream&s,const osoba&o);
    friend ostream&operator<<(ostream&s,const osoba*wsk);
};
ostream&operator<<(ostream&s,const osoba&o)
{
    s<<o.nazwisko;
    return s;
}
ostream&operator<<(ostream&s,const osoba*wsk)
{
    s<<wsk->nazwisko;
    return s;
}
template<class twojtyp>
class wektor
{
    twojtyp tabl[15];
    int ileobiektow;
public:
    wektor():ileobiektow(0){}
    int wstaw(const twojtyp&nowy,int gdzie=-1);
    void usun(int nr);
    twojtyp&cona(int pozycja){return tabl[pozycja];}
    friend ostream&operator<<(ostream&stru,wektor<twojtyp>&x);
protected:
    void rozsun(int pozycja);
    void zsun(int nr);
};

template<class twojtyp>
void wektor<twojtyp>::rozsun(int pozycja)
{
    for(int i=ileobiektow;i>pozycja;i--)
    {
        tabl[i]=tabl[i-1];
    }
}
template<class twojtyp>
void wektor<twojtyp>::zsun(int nr)
{
    for(int i=nr;i<ileobiektow;i++)
    {
        tabl[i]=tabl[i+1];
    }
}
template<class twojtyp>
int wektor<twojtyp>::wstaw(const twojtyp&nowy,int gdzie)
{
    if(ileobiektow==15)
    {
        cout<<"Wektor pelny"<<endl;
        return 0;
    }
    if(gdzie<0 || gdzie>ileobiektow)
    {
        gdzie=ileobiektow;
    }
    rozsun(gdzie);
    tabl[gdzie]=nowy;
    ileobiektow++;
    return 1;
}

template<class twojtyp>
void wektor<twojtyp>::usun(int nr)
{
    if(nr<ileobiektow)
    {
       zsun(nr) ;
       ileobiektow--;
    }
}
template<class twojtyp>
ostream&operator<<(ostream&stru,wektor<twojtyp> &spis)
{
    stru<<"";
    for(int i =0;i<spis.ileobiektow;i++)
    {
      stru<<i<<") "<<spis.tabl[i]<<"";
    }
    stru<<endl;
    return stru;
}
int main()
{
    osoba
        wloch("wloch"),
        niemiec("niemiec"),
        austryjak("austryjak"),
        polak("polak");
    cout<<"Wloch: "<<wloch<<endl;

    wektor<osoba>muzycy;
    //muzycy.wstaw(wloch);
}

 


Viewing all articles
Browse latest Browse all 21942

Trending Articles


TRX Antek AVT - 2310 ver 2,0


Автовишка HAULOTTE HA 16 SPX


POTANIACZ


Zrób Sam - rocznik 1985 [PDF] [PL]


Maxgear opinie


BMW E61 2.5d błąd 43E2 - klapa gasząca a DPF


Eveline ➤ Matowe pomadki Velvet Matt Lipstick 500, 506, 5007


Auta / Cars (2006) PLDUB.BRRip.480p.XviD.AC3-LTN / DUBBING PL


Peugeot 508 problem z elektroniką


AŚ Jelenia Góra