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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:23:35+00:00 2026-06-04T22:23:35+00:00

I have a constructor prototype that looks like: template <typename type_position> window( const int

  • 0

I have a constructor prototype that looks like:

template <typename type_position> window(
    const int size[2],
    const char* caption="Window", const SDL_Surface* icon=NULL,
    bool fullscreen=false, bool vsync=true, bool resizable=false, int multisample=0,
    type_position position=type_position(0)
)

I then want to construct an instance:

new window(screen_size,"My Window",NULL,fullscreen);

The issue (I assume) is that T cannot be specified explicitly (i.e., it could be int or long or short, etc.). I get the error:

error C2660: ‘window’ : function does not take 4 arguments

I then tried to specify the type:

new window<int>(screen_size,"My Window",NULL,fullscreen);

But that doesn’t work:

error C2512: ‘window’ : no appropriate default constructor available
error C2062: type ‘int’ unexpected

I’ve done some research, and about the closest I could get was similar to that is the question “C++ template function default value“, except that in my case, the template parameter can be inferred from the first argument.

So, am I stuck or is there something I’m missing?

  • 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-06-04T22:23:37+00:00Added an answer on June 4, 2026 at 10:23 pm

    You can’t a provide explicit template argument list for a constructor, and a template parameter cannot be deduced from a default function argument, so the type_position position function parameter needs to be provided explicitly (not defaulted) in order to deduce the type.

    As that is the final parameter, it prevents you using any of the contructor’s default arguments. You could re-order the constructor parameters so the type_position is given first, or you could add a dummy argument that allows it to be deduced:

    template <typename type_position> window(
      type_position dummy,
      const int size[2],
      const char* caption="Window", const SDL_Surface* icon=NULL,
      bool fullscreen=false, bool vsync=true, bool resizable=false, int multisample=0,
      type_position position=type_position(0)
    );
    

    Then call it with a dummy first parameter of the type to be deduced:

    new window(1, screen_size,"My Window",NULL,fullscreen);
    

    Alternatively, if you’re using C++11, you can provide a default template argument:

    template <typename type_position = int> window(
      const int size[2],
      const char* caption="Window", const SDL_Surface* icon=NULL,
      bool fullscreen=false, bool vsync=true, bool resizable=false, int multisample=0,
      type_position position=type_position(0)
    );
    

    Alternatively, decide if you really want a template constructor with a parameter that needs to be deduced. What do you plan to do with the type_position type if you don’t know what it is in advance? Is it valid for someone to call that constructor with a std::string as the position parameter? Or a vector<double>? It might make sense, depending on what your type does, but it doesn’t always make sense.

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

Sidebar

Related Questions

I have a constructor that looks like this (in c++): Interpreter::Interpreter() { tempDat ==
I have a case that uses view inheritance, and my code looks essentially like:
I have the below prog Object.prototype.inherit = function(baseConstructor) { this.prototype = (baseConstructor.prototype); this.prototype.constructor =
I have Constructor Tree(int a, int b, int c) and second Constructor Tree(int a,
I have a constructor (for an auto generated class) that has 255 paremeters. Using
I have a constructor that has a series of classes and functions within it
I have a constructor signature like this public NavigationLink(Func<String> getName, Func<UrlHelper, String> getURL, Func<bool>
I want to have a constructor with an argument that gets inherited by all
I have a C# prototype that is heavily data parallel, and I've had extremely
I have the following legacy code that I'd like to remove eval from: eval('view

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.