Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7619399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:40:40+00:00 2026-05-31T03:40:40+00:00

Usually, books usually discourage the use of conversion operators when wrapping up c structs.

  • 0

Usually, books usually discourage the use of conversion operators when wrapping up c structs. For example the c++ string, which is (believed to be) a wrapper of a C char array, does not provide a conversion operator. Instead it gives the the method c_str().

However, I seriously think my case may be an exception. I am wrapping up an SDL_Surface. Here’s the class declaration.

/** Wraps up SDL_Surface **/
class surface
{
    SDL_Surface* _surf;
public:
    /** calls SDL_LockSurface().
     ** throws surface_lock_exception on failure.
     **/
    void lock();

    /** calls SDL_UnlockSurface() **/
    void unlock();

    /** calls SDL_LoadBMP().
     ** throws image_load_exception on failure.
     **/
    void load_bmp(const string&);

    /** calls SDL_FreeSurface(). **/
    void free();

    /** destructor. Also free()s the internal SDL_Surface. **/
    ~surface();
};

In this case, I seriously think I should add a conversion operator to SDL_Surface* for easy compatibility with other SDL Functions that require an SDL_Surface*.

What do you think:

  1. Would a conversion operator be prudent?
  2. Or Should I use a method like c_str()?
  3. Or is there another, better solution?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:40:42+00:00Added an answer on May 31, 2026 at 3:40 am

    Although providing a conversion operator would be required to pass your new-fangled wrapper class to existing SDL library functions, you must ask yourself if you really need to.

    The reason that c_str() exists at all is so that us C++ programmers can use std::string and then call all those archaic runtime library functions that never heard of it. If you’re writing a C++ program from the ground up, would any of your function calls take a const char*? No, they’d take a const std::string&, perhaps.

    So, if you are wrapping up SDL in a nice library, then one must ask if you should ever be exposing the underlying data structures. Surely your library will always want to talk to a Surface and not care what is going on underneath?

    So my preferred solution would be to hide it away and let those classes that deal with working with the underlying SDL library, do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Usually, when using Windows Authentication, the software (eg Internet Explorer) tries to use Windows
I read a lot of books about how to code right and usually they
When reading about the crossover part of genetic algorithms, books and papers usually refer
I'm working on the example at http://java.sun.com/docs/books/tutorial/uiswing/examples/components/GenealogyExampleProject/src/components/GenealogyExample.java I wanted to customize it in a
Programming language books usually explain that value types are created on the stack, and
If you instantiate a new HashSet, you usually use the Set interface to work
Does anyone know of papers/books/etc. that document patterns for databases? For example, one common
Whenever I look at real code or example socket code in books, man pages
I usually hardwire the xpath in the xqueries like so: let $xml := <books>
Books usually say that if the classes get too big to manage, rethink the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.