allora...
l'errore di prima nn c'è ma in compenso me ne dà altri relativi all'iostream:
vi riposto codie e compilazione:
#include <iostream>
#include "bosco.h"
int Bosco:iantatiS = 0;
int Bosco::abbattutiS = 0;
Bosco::Bosco(){
nPiantati=0;
nAbbattuti=0;
testa=NULL;
}
Bosco::Bosco(int t, int n){
t=t>0?t:1;
n=n>0?n:1;
testa=new elem;
testa->pun=NULL;
testa->anni=t;
testa->nAlberi=n;
nPiantati=n;
nAbbattuti=0;
piantatiS+=nPiantati;
}
void Bosco::copia (const Bosco& b){
nPiantati=b.nPiantati;
nAbbattuti=b.nAbbattuti;
piantatiS+=nPiantati;
abbattutiS+=nAbbattuti;
elem*q=b.testa,*w;
if (q==NULL) {
testa=NULL;
return;
}
testa=new elem;
testa->anni=q->anni;
testa->nAlberi=q->nAlberi;
w=testa;
q=q->pun;
while(q!=NULL){
w->pun=new elem;
w=w->pun;
w->anni=q->anni;
w->nAlberi=q->nAlberi;
q=q->pun;
}
w->pun=NULL;
}
void Bosco::distruggi (){
if (testa==NULL) return;
elem *q=testa,*w;
while (q!=NULL){
w=q->pun;
delete q;
q=w;
}
}
Bosco& Bosco:perator = (const Bosco& b){
if (this!=&b){
distruggi();
copia(b);
}
return *this;
}
Bosco& Bosco:ianta(int t, int n){
t=t>0?t:1;
n=n>0?n:1;
elem*q=testa,*w;
while (q!=NULL && q->anni<t){
w=q;
q=q->pun;
}
if (q!=NULL && q->anni==t){
q->nAlberi+=t;
nPiantati+=t;
piantatiS+=t;
return *this;
}
elem* k=new elem;
k->anni=t;
k->nAlberi=n;
nPiantati+=n;
piantatiS+=n;
if (q==testa){
testa=k;
k->pun=q;
}
else {
w->pun=k;
k->pun=q;
}
return *this;
}
int Bosco::abbatti(int t){
if (testa==NULL || t<=0) return 0;
int abbattemp=0;
elem*q=testa,*w;
while (q!=NULL && q->anni<t){
w=q;
q=q->pun;
}
if (q==NULL) return 0;
if (q==testa) testa=NULL;
else w->pun=NULL;
while (q!=NULL){
w=q->pun;
abbattemp+=q->nAlberi;
nAbbattuti+=q->nAlberi;
abbattutiS+=q->nAlberi;
delete q;
q=w;
}
return abbattemp;
}
int Bosco::quanti(int t){
if (testa==NULL || t<=0) return 0;
int conta=0;
elem*q=testa;
while (q!=NULL && q->anni<t)
q=q->pun;
if (q==NULL) return 0;
while (q!=NULL){
conta+=q->nAlberi;
q=q->pun;
}
return conta;
}
ostream& operator << (ostream& os, const Bosco& b){
os << '[';
int condizione=0;
Bosco::elem *q=b.testa;
while (q!=NULL){
if (condizione) os << ", ";
condizione=1;
os << q->nAlberi << ':' << q->anni;
q=q->pun;
}
os << ']';
return os;
}
Compiling...
bosco.cpp
c:\documents and settings\gianluigi\desktop\prove\prove\bosco.h(2) : error C2143: syntax error : missing ';' before '&'
c:\documents and settings\gianluigi\desktop\prove\prove\bosco.h(2) : error C2433: 'ostream' : 'friend' not permitted on data declarations
c:\documents and settings\gianluigi\desktop\prove\prove\bosco.h(2) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\gianluigi\desktop\prove\prove\bosco.h(2) : error C2061: syntax error : identifier 'ostream'
c:\documents and settings\gianluigi\desktop\prove\prove\bosco.h(2) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\gianluigi\desktop\prove\prove\bosco.h(2) : error C2805: binary 'operator <<' has too few parameters
.\bosco.cpp(135) : error C2143: syntax error : missing ';' before '&'
.\bosco.cpp(135) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\bosco.cpp(135) : error C2086: 'int ostream' : redefinition
c:\documents and settings\gianluigi\desktop\prove\prove\bosco.h(2) : see declaration of 'ostream'
.\bosco.cpp(135) : error C2065: 'os' : undeclared identifier
.\bosco.cpp(135) : error C2059: syntax error : 'const'
.\bosco.cpp(135) : error C2143: syntax error : missing ';' before '{'
.\bosco.cpp(135) : error C2447: '{' : missing function header (old-style formal list?)
10 9