Return a vector of type ...

Hello everyone,

i'm trying to create a method in a class that return a vector of objects.

In the class i create this object

 
vector<CObject> My_Objects;


where i put some objects in.

Now, i would like to create a method that returns this vector

1
2
3
vector<CObject> CCharacter::inventory() {
...
}


but this doesn't work. I get: \include\character.h|114|error: prototype for 'std::vector<CObject> CCharacter::inventory()' does not match any in class 'CCharacter'|

could someone give me help?
Does your class definition contain:
1
2
3
4
5
6
class CCharacter // ...
{
  // ...
  vector<CObject> inventory();
  // ...
};


Furthermore, why isn't the member function const?
Thank you. My class definition was different. I solved now.

"Furthermore, why isn't the member function const? "

Could you please elaborate more on this?

why my member function should be const?
Because it makes no changes to the state of the object. If you make it const, then it can be called on a const object.
OK, thank you for the explanation
You're welcome.
Topic archived. No new replies allowed.