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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:33:55+00:00 2026-05-20T03:33:55+00:00

Is it somehow possible to reflect the type of the argument of a function

  • 0

Is it somehow possible to reflect the type of the argument of a function at compile time?

So that

int b = add(3, 6)

Would result in a template instantiation in the form of

int add(int a, int b) { return a + b }

out of some however declared function template

A add(A a, B b) { return a + b }

I don’t know if that is possible with templates they do not really seem to be made for heavy meta-programming.

  • 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-20T03:33:56+00:00Added an answer on May 20, 2026 at 3:33 am

    Templates do all their magic at compile time, but that seems to be quite adequate for what you’re asking:

    template <class T>
    T add(T a, T b) {  return a + b; }
    

    It does get a bit more complex when the two might not match, so (for example) you could add an int to a double and get a double result. The current standard doesn’t really support that1; with C++0x you can look into auto and decltype for such tasks.

    1Though Boost typeof will often do the job.

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

Sidebar

Related Questions

Is it somehow possible? I want that to enable compile-time passing of arguments. Suppose
Is this possible somehow to generate a GUID in C#, that mostly corresponds to
while debugging a C++ program with GDB, is it possible somehow to add comments
Is it somehow possible to customize or subclass System.Windows.Forms.ColorDialog to add a few buttons?
is it somehow possible to call a rails function or to access a rails
Is it somehow possible on Swing to set a TitledBorder transparent so that a
Is it somehow possible to send a function to another function for it to
Is it somehow possible that instead of: Button btnNextWord = (Button) this.findViewById(R.id.btnNextWord); Eclipse automatically
Is that somehow possible to access one datastore? Or access one app from different
Is it somehow possible to unmask a PasswordTextBox ? I would like to have

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.