Hello
I am trying to pass a array of object to a member function of that class but not successfull. I gone throgh lots of article and document also follow this thread in Daniweb Click Here
This thread is good to understand how to pass an array of object to a function which is not a member function.
But when take the void showAges(fish fishes[]) inside the class compiler give an error 'Undefined structure fish'.
How can I pass the array to member function.
I made some chages to check if I'm right but NO...!
#include <iostream.h>
#include <conio.h>
class fish
{
private:
int age;
public:
int getAge()
{
return age;
}
void setAge(int newage)
{
age = newage;
}
void showAges(fish fishes[]);
};
void fish::showAges(fish fishes[])
{
cout << "fish 1 age is: " << fishes[0].getAge() << endl;
cout << "fish 2 age is: " << fishes[1].getAge() << endl;
cout << "fish 3 age is: " << fishes[2].getAge() << endl;
}
int main()
{
fish myFish[3];
myFish[0].showAges(myFish);
cout << endl;
myFish[0].setAge(10);
myFish[1].setAge(20);
myFish[2].setAge(30);
myFish[0].showAges(myFish);
cin.get();
return 0;
}