I was dealing with templates this time. Pretty neat concept, I have to admit. However, there is a problem: an error comes when I try to something like this:
/// ----------------------------------------------
/// @brief Sets a character as an owner of "this".
/// @return Returns "this" with an owner.
/// ----------------------------------------------
template<int I>
template<int J>
Bobby::Item<I>& Bobby::Item<I>::setOwner(Bobby::Character<J>& character){
moOwner = character;
return *this;
}
NOTE: This is not the full code I have written. Code is cut due the limitations of amount of text.
So, this the error I get: |202|error: no 'Bobby::Item<I>& Bobby::Item<<anonymous> >::setOwner(Bobby::Character<J>&)' member function declared in class'Bobby::Item<<anonymous> >'|
There is no point in using templates here. You have a small set of possible arguments and you intend to write a specialization for every one of them. Just use separate classes..
The basic idea behind this is that Item is a templateclass, which has been specialized in order to make it's use more flexible. For example, if I create an object using Bobby::Item<Bobby::ITEM_COLLECTIBLE> or Bobby::Item<Bobby::ITEM_TOOL>, they would be similiar kind of classes yet differenting crucially.
Character (which is defined somewhere else in my project codes) will use Bobby::Item<Bobby::ITEM_TOOL> (see my code above for more).
Why have you declared Item twice (ambiguous)? That said, why does Item inherit itself?
I can't understand what you mean. I have inherited Item<ITEM_COLLECTIBLE> from Item<ITEM_TOOL>.
About the error, I feel that it's there because you're not referring to the specialization, and the function doesn't exist in the normal template. Try something like
About the error, I feel that it's there because you're not referring to the specialization, and the function doesn't exist in the normal template. Try something like