I’m wrapping up a struct and functions related to that struct in a C++ class.
class Surface
{
public:
operator SDL_Surface* () { return this->surf_; } // good idea?
private:
SDL_Surface* surf_;
}
Is using a conversion operator in this case a good idea? Or will I run into problems? Any alternatives?
It’s a terribly bad idea. The
SDL_Surface*should remain entirely encapsulated within the class, accessible only to other classes which are part of your SDL abstraction. In addition, you should be smart pointing to it to ensure it’s safe destruction.