Well there are a number of programming errors. First off, you changed the return type of your object::getwname(int num) from string* to int* when you declared it. The second and third errors are in returning pointers to pointers in your object class when you declared you would be returning a single pointer. See below.
int* object::getwid(int num) { return oweapon[num].getwid();}string* object::getwname(int num) { return oweapon[num].getwname();}
I removed the & in front of the variables because you do not want to return the adress of the variable because you previously defined in getwid() and getwname() that you would already be returning the address already.
The next errors aren't compile errors but runtime errors.
for(int a=0; a<10; a++) { cout<<o.getwid(a)<<endl; } for(int b=0; b<10; b++) { cout<<o.getwname(a)<<endl; }
Because you are dealing with pointers to variables you can't simply output their values with cout. You must dereference them using the * symbol. Like so. Also note that in your for loop that increments 'b' you should put o.getwname(
b) instead of 'a' as you are incrementing that and 'a' already = 10.
for(int a=0; a<10; a++) { cout<< *o.getwid(a)<<endl; } for(int b=0; b<10; b++) { cout<< *o.getwname(b)<<endl; }
It should run as expected now. However, in terms of coding this to make it easier to understand and even save you some typing, I would avoid returning pointers of variables that there is only one instance of (eg. returning int* getwid() in class weapon). Instead of having to create duplicate functions in your object class for each weapon function you create. You can simply return a pointer to a specific weapon and then use the pointer to call functions from that class.
class weapon{private: int id; string name;public: int getwid() { return id; } string getwname() { return name; }};class object{private: weapon oweapon[10];public: weapon *getweapon(int num) { return &oweapon[num]; }};
Then in main you would call..
for (int a=0;a < 10;a++){ weapon *currentweapon = o.getweapon(a); cout << currentweapon->getwid() << endl; cout << currentweapon->getwname() << endl; //or even o.getweapon(a)->getwid() will work but may look confusing.}
Hope that helps. Good luck in your programming.
Most of our obstacles would melt away if, instead of cowering before them, we should make up our minds to walk boldly through them.- Orison Swett Marden