又是输出流出错了,帮帮忙啊

时间:2022-04-25 05:46:54
	friend  ostream& operator<<(ostream& o,Ecosystem& e){
for(int i=0;i<5;i++){
return o<<e.queue[i];
}
return o<<sp;
}

class Ecosystem{
Time t;
Enviornment current;
float sp;
int s;
Queue queue[5];
int total;
public:
friend  ostream& operator<<(ostream& o,Ecosystem& e){
for(int i=0;i<5;i++){
return o<<e.queue[i];
}
return o<<sp;
}
Ecosystem(){
t.set(1);
total=0;
current.set(t);
queue[0].set(s,0,current);
queue[1].set(s,1,current);
queue[2].set(s,2,current);
queue[3].set(s,3,current);
queue[4].set(s,4,current);
for(int i=0;i<4;i++){
total+=queue[i].total;
}
}
ostream& run(ostream& o,int n){
for(int i=0;i<n;i++){
int l=4*base();
int k=4*base();
if(l>k){
swap(l,k);
}
int g=queue[l].n*base();
int h=queue[k].n*base();
Species* s1=&queue[l].species[g];
Species* s2=&queue[k].species[h];
Queue* q1=&queue[l];
Queue* q2=&queue[k];
q1->statistic-=s1->statics;
total-=q1->total;
q1->total-=s1->amount;
s1->change(int(s1->amount+s1->adaptness*s1->amount-s2->amount*0.1*s1->amount*s2->amount/total/total*abs(s1->strength-s2->strength)*1/(l-k)/(l-k)));
q1->statistic+=s1->statics;
q1->total+=s1->amount;
total+=q1->total;
q2->statistic-=s2->statics;
total-=q2->total;
q2->total-=s2->amount;
s2->change(int((s2->amount)+(s2->adaptness)*(s2->amount)-(s1->amount)*(s1->amount)*(s2->amount)/total/(total-1)*abs(s1->strength-s2->strength)*1/(l-k)/(l-k))*0.7);
q2->statistic+=s2->statics;
q2->total+=s2->amount;
total+=q2->total;
int temp=0;
for(int i=0;i<5;i++){
temp+=queue[i].statistic;
}
sp=1-temp/total/(total-1);
}
return o<<*this<<endl;
}
};
error C2326: 'class std::basic_ostream<char,struct std::char_traits<char> > &__cdecl Ecosystem::operator <<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Ecosystem &)' : 
class Species{
public:
string name;
int amount;
float adaptness;
float strength;
long int statics;
Enviornment best;
public:
Species(){
float temp1=f1();
float temp2=f1();
float temp3=f1();
best.set(temp1,temp2,temp3);
}
void change(int a){
amount=a;
statics=a*(a-1);
}
friend ostream& operator<<(ostream& o,Species& s){
o<<s.amount<<endl;
    return o;
}

void init(string na="aaa",int n=1000){
name=na;
amount=n;
        statics=amount*(amount+1);
}
void reset2(int i,Enviornment& current){
if(i==0){
strength=s1(i);
adaptness=s2(i)*f(best,current)/5.0-0.2*1/5.0;
}
if(i==1){
strength=s1(i);
adaptness=s2(i)*f(best,current)/5.0+0.1/5;
}
if(i==2){
strength=s1(1);
adaptness=s2(i)*f(best,current)/7.0+0.05;
}
if(i==3){
strength=s1(1);
adaptness=s2(i)*f(best,current)*0.1+0.1;
}
}
void reset(string na,int am,int i,Enviornment& current){
name=na;
amount=am;
reset2(i,current);
}
void reset(int am){
amount=am;
statics=amount*(amount-1);
}
ostream& print(ostream& o){
return o<<amount<<" ";
}
};
class Queue{
Species* species;
int amount;
int n;
int level;
long int statistic;
int total;
int remain;
public:
friend class Ecosystem;
Queue(){}
void set(int nn,int le,Enviornment& current){
level=le;
amount=nn;
n=0;
species=new Species[nn];
statistic=0;
total=sum;
for(int i=0;i<4-level;i++){
total=total*0.1;
}
remain=total;
init(current);
}
~Queue(){
delete []species;
}
void push(Species& s){
if(amount==n){cout<<"full"<<endl;exit(0);}
species[n]=s;
statistic+=s.statics;
n++;
}
Species* factory(Enviornment& current){
Species* s=new Species();
s->reset2(level,current);
return s;
}
void init(Enviornment& current){
int s=amount*(level+1)/15;
for(int i=0;i<s;i++){
Species* s1=factory(current);
if(i==s-1){s1->amount=remain;}
s1->amount=remain*base();
remain-=s1->amount;
this->push(*s1);
}
}
void remove(int i){
if(i>=n || i<=0){
return;
}
statistic-=species[i].amount*(species[i].amount-1);
total-=species[i].amount;
for(int j=i+1;j<n;j++){
species[j]=species[j+1];
n--;
}
}
friend ostream& operator<<(ostream& o,Queue& q){
for(int i=0;i<q.n;i++){
return o<<q.species[i];
}
}
};

7 个解决方案

#1


    friend  ostream& operator<<(ostream& o,Ecosystem& e){
        for(int i=0;i<5;i++){
            return o<<e.queue[i];
        }
        return o<<sp;
    }
错了,应该
    friend  ostream& operator<<(ostream& o,Ecosystem& e){
        for(int i=0;i<5;i++){
            o<<e.queue[i];
        }
        return o;
    }

#2


VC++6.0??

换个编译器

#3


引用 1 楼 happymawolf 的回复:
    friend  ostream&amp; operator<<(ostream&amp; o,Ecosystem&amp; e){
        for(int i=0;i<5;i++){
            return o<<e.queue[i];
        }
        return o<<sp;
    }
错了,应该
    friend  os……

sp也要输出咋办呢?

#4


这样
friend ostream& operator<<(ostream& o,Ecosystem& e){
  for(int i=0;i<5;i++){
  o<<e.queue[i];
  }
  o<<sp;
  return o;
 }

#5


vc++6.0不好使,其他的会好使??
引用 2 楼 bargio_susie 的回复:
VC++6.0??

换个编译器

#6


引用 4 楼 happymawolf 的回复:
这样
friend ostream&amp; operator<<(ostream&amp; o,Ecosystem&amp; e){
  for(int i=0;i<5;i++){
  o<<e.queue[i];
  }
  o<<sp;
  return o;
 }

原来是e.sp没写,谢谢你啊

#7


又是输出流出错了,帮帮忙啊

#1


    friend  ostream& operator<<(ostream& o,Ecosystem& e){
        for(int i=0;i<5;i++){
            return o<<e.queue[i];
        }
        return o<<sp;
    }
错了,应该
    friend  ostream& operator<<(ostream& o,Ecosystem& e){
        for(int i=0;i<5;i++){
            o<<e.queue[i];
        }
        return o;
    }

#2


VC++6.0??

换个编译器

#3


引用 1 楼 happymawolf 的回复:
    friend  ostream&amp; operator<<(ostream&amp; o,Ecosystem&amp; e){
        for(int i=0;i<5;i++){
            return o<<e.queue[i];
        }
        return o<<sp;
    }
错了,应该
    friend  os……

sp也要输出咋办呢?

#4


这样
friend ostream& operator<<(ostream& o,Ecosystem& e){
  for(int i=0;i<5;i++){
  o<<e.queue[i];
  }
  o<<sp;
  return o;
 }

#5


vc++6.0不好使,其他的会好使??
引用 2 楼 bargio_susie 的回复:
VC++6.0??

换个编译器

#6


引用 4 楼 happymawolf 的回复:
这样
friend ostream&amp; operator<<(ostream&amp; o,Ecosystem&amp; e){
  for(int i=0;i<5;i++){
  o<<e.queue[i];
  }
  o<<sp;
  return o;
 }

原来是e.sp没写,谢谢你啊

#7


又是输出流出错了,帮帮忙啊