void fishing(vector<Fish*> &basket);
int printBasket(vector<Fish*> &basket);
int main()
{
vector<Fish*> FishVec;


Fish* aFish;

int totalweight=0;
int i=0;
while (totalweight<15000)
{
fishing(FishVec);

aFish=FishVec.at(i);

aFish->printMe();

if (aFish->acceptable())
{
totalweight+=aFish->getWeight();
cout<<"total weight:"<<totalweight<<endl;
cout<<" Has been put in the basket"<<endl;



}
else
{

cout<<" Was released"<<endl;
}
i++;
cout<<endl;
}
}
void fishing(vector<Fish*> &basket)
{
int i=RandomInt(1,4);
Fish* aFish;

if (i==1)
{
cout<<"caought:";
aFish=new AustralianBass();
basket.push_back(aFish);

}
else if(i==2)
{
cout<<"caought:";
aFish=new ShortFinedEel();
basket.push_back(aFish);
}
else if (i==3)
{
cout<<"caought:";
aFish=new EelTailedCatfish();
basket.push_back(aFish);
}
else if (i==4)
{
cout<<"caought:";
aFish=new GippslandPerch();
basket.push_back(aFish);
}

}
int printBasket(vector<Fish*> &basket) //suposed to be print content of the basket but it     is not working what is wrong with this .
{

Fish* aFish;
for(int i=0;i<basket.size();i++)
{
aFish=(basket.at(i));
aFish->printMe();
}
return 0;
}

Your printbasket function seems to be fine.

This is not a solution but it would make it easier to read if you used indention to show scope.

The problem does not appear to be in printbasket.

Look at fish::printme. Are the different fish classes derived from the fish class? Calling printMe() from a Fish pointer will call the fish handler if no inhertitance is used. You obviously want it to call fishtype::printme()

This is what you need, if you don't already know about virtual methods and inheritance you should read about it.


class Fish
{
public:
virtual void PrintMe()=0;
};

class FishType : public Fish
{
virtual void PrintMe();
};

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.