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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:47:55+00:00 2026-05-31T17:47:55+00:00

Consider the following short program: #include <type_traits> #include <iostream> using namespace std; template <typename

  • 0

Consider the following short program:

#include <type_traits>
#include <iostream>
using namespace std;

template <typename T>
void fn( T t ) {
    cout << "T is reference: " <<
        boolalpha << is_reference<T>::value << endl;
}


int main( void ) {
    int x = 0;
    int& r = x;
    fn( r );
}

Running this program, I’m getting: T is reference: false.
Would would be the explanation?

  • 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-31T17:47:57+00:00Added an answer on May 31, 2026 at 5:47 pm

    The C++ 2003 template type deduction tries to find a matching argument type. If you want to take a reference as argument you need to say so and possibly overload the template appropriately. Changing referenceness would actually generally not be what you want (although you could remove the reference part of the deduced type). Generally, the concepts implemented by a reference type are quite different from those used for values. Also note that r is just another name for x for the purpose of type deduction and overload resolution.

    In C++ 2011 you can ask the compiler to retain a bit more type information: when deducing the type in a template using rvalue reference notation (i.e. T&& for a template argument T), the type will be deduced to be a reference with cv-qualuiiers applied appropriately for lvalues and a value type for non-lvalues. That is the deduced type essentially depends on whether the argument is a temporary object (or at least is made to look like one).

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

Sidebar

Related Questions

Consider the following code: namespace ConsoleApplication1 { class Program { static void Main(string[] args)
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider the following short code snippet. namespace B { public class Foo { public
Background Consider the following code: #include <utility> namespace ns { struct foo { foo()
Consider the following code: void f(byte x) {print(byte);} void f(short x) {print(short);} void f(int
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider the following program: $x=12345678901.234567000; $y=($x-int($x))*1000000000; printf(%f:%f\n,$x,$y); Here's what is prints: 12345678901.234568:234567642.211914 I was
Consider the following snippet: int i = 99999999; byte b = 99; short s
Consider the following situation: class MyFoo { public: MyFoo(); ~MyFoo(); void doSomething(void); private: unsigned

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.