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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:29:56+00:00 2026-05-29T09:29:56+00:00

Having the following code: template<typename T, typename OutStream = std::ostream> struct print { OutStream

  • 0

Having the following code:

template<typename T, typename OutStream = std::ostream> struct print {
  OutStream &operator()(T const &toPrint, OutStream &outStream = std::cout) const {
    outStream << toPrint;
    return outStream;
  }
};

This call is erroneous:

print<int>(2);

Error message:

1>main.cpp(38): error C2440: '<function-style-cast>' : cannot convert from 'int' to 'print<T>'
1>          with
1>          [
1>              T=int
1>          ]
1>          No constructor could take the source type, or constructor overload resolution was ambiguous

This call is not erroneous:

print<int> intPrinter;
intPrinter(2);

Can I use a function object somehow without its instantiation?
I cannot use a template function here, because I need partial specialization capabilities.

  • 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-29T09:29:57+00:00Added an answer on May 29, 2026 at 9:29 am

    I think that you want to say

    print<int>()(2);
    

    Here, the first parens create a temporary print<int> object by calling the (zero-argument) constructor, then the second parens actually invoke the function call operator on that object. The error you’re getting now is caused by the fact that

    print<int>(2);
    

    Is interpreted as a typecast expression to convert 2 into a print<int>, which isn’t what you want (and also isn’t legal).

    Hope this helps!

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

Sidebar

Related Questions

Good day everybody! Having the following code: template<typename T, typename OutStream = std::ostream> struct
I'm having compile time trouble with the following code: template <typename T, template <class
With the code: template <typename T> class MyClass { public: MyClass(const MyClass& other) {
I'm having a weird problem, I have the following code in my page.php template
I m having the following code, however, I can see that the radio button
I am having following peice of code ,where in i am trying to serialize
Having sorted the tag_counts hash via the following code: sorted_tags = Contact.tag_counts.sort{ |x,y| x.name.downcase
I'm having an issue with the following code: private void DataPortal_Fetch(TaskCriteria criteria) { using
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
I'm having troubles with the following code: <link type=text/css href=http://jqueryui.com/latest/themes/base/jquery.ui.all.css rel=stylesheet /> <script type=text/javascript

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.