I’ve been recently writing simple game in C++ with SFML. Here’s my question:
In SFML library there is a template class Vector2<T> (specifically I’d be using Vector2f). Unfortunately, it doesn’t have any method to rotate itself, so I came with the idea to write one. But as I wrote:
template<typename T> void Vector2<T>::Rotate(float a);
the compiler says that I can’t do things like this:
printable.h:31:53: error: no ‘void sf::Vector2<T>::Rotate(float)’ member function declared in class ‘sf::Vector2<T>’
Is it possible to add custom method like this? Or should I wrap Vector2f into my own class?
What you’re thinking of is called “monkey patching” or categories and is not available in C++. You can derive from that class to add that functionality or create a
friendfunction to implement what you’re trying to do. (Functions defined asfriendinside a class definition have access to an object’s internal state)