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 7089419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:55:10+00:00 2026-05-28T07:55:10+00:00

See,I have this code: template<typename T=int>struct color { T red, green, blue; color(T r,

  • 0

See,I have this code:

template<typename T=int>struct color
{
    T red, green, blue;
    color(T r, T g, T b)
    :red(r), green(g), blue(b)
    {
    }

    #ifdef SDL_BACKEND
    template<typename R,typename S> R map(S surf)
    {
        return SDL_MapRGB(surf->format,red,green,blue);
    }
    #endif /* SDL_BACKEND */
};

and I use it here:

pro::color<int> black(0,0,0);
SDL_FillRect(screen, 0, black.map(screen));

Now here’s the error I’m getting:

error: no matching function for call to ‘pro::color::map(SDL_Surface*&)’|

I’m not that experienced in templates, so I haven’t seen this error before. What exactly is the problem?

NOTE: I didn’t tag this with the “SDL” tag, because IMHO this question is more related to templates , the fact that I am using SDL is irrelevant. Also I’m using gcc-4.4x with -std=c++0x.

  • 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-28T07:55:10+00:00Added an answer on May 28, 2026 at 7:55 am

    This has nothing to do with meta programming. It’s just a matter of using templates correctly. The return type cannot be deduced, so you have to specify it; either in the function or in the template instantiation. I.e., pick one of these two:

    // Version #1: Change function definition
    template<typename S> Uint32 map(S surf) { return SDL_MapRGB(surf->format,red,green,blue); }
    
    
    // Version #2: Change invocation
    black.map<Uint32>(screen);
    

    (In fact, I don’t really understand why you need a template here at all. Why not just make the function into Uint32 map(SDL_Surface *)?)

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

Sidebar

Related Questions

I have this code below. As you can see I am passing two variables
how to see items that i pick on ListView ? i have this code:
I have been looking over this code for the past hour, I cant see
I've got this sample code: struct A { int foo() { return 27; }
I have a struct which indicates a trait: template<typename T> struct FooTraits { static
I have this code that relies on SFINAE and default template arguments. It works
i have this template code: <script type=text/javascript> $(function(){ //submit new messages when the user
I have this: As you can see I currently have a conditional to include
I have this control (see picture). I like when check one option in this
I have this edmx model (see below) and I would like to add an

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.