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

  • Home
  • SEARCH
  • 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 8764099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:56:45+00:00 2026-06-13T15:56:45+00:00

The following errors due to the const int specialization: #include <iostream> using std::cout; using

  • 0

The following errors due to the const int specialization:

#include <iostream>
using std::cout;
using std::endl;

template <typename T> void g(T val)
{
    cout << "unknown" << endl;
}

template <> void g(int && val)
{
    cout << "int &&" << endl;
}

template <> void g(const int && val)
{
    cout << "const int &&" << endl;
}

template <> void g(int & val)
{
    cout << "int &" << endl;
}

template <> void g(const int & val)
{
    cout << "const int &" << endl;
}

template <> void g(int val)
{
    cout << "int" << endl;
}

template <> void g(const int val)  //redefinition here
{
    cout << "const int" << endl;
}

int main() {}

error: redefinition of 'g'
template <> void g(const int val)
                 ^

Why are T& and T&& distinct from const T& and const T&& but T is not distinct from const T?

  • 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-13T15:56:47+00:00Added an answer on June 13, 2026 at 3:56 pm

    Because top-level const-ness of function parameters is an implementation detail of the function. For example, the following is valid:

    // Prototype
    void foo(int c);
    
    // Implementation
    void foo(int const c) { ... }
    

    Since the argument is passed by value, the caller doesn’t really care whether the function is going to modify its own private copy. Therefore, top-level const-ness is not part of the function signature.

    Note that this only applies to top-level const-ness! int and int const are equivalent in a function prototype, as are int * and int * const. But int * and int const * are not.

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

Sidebar

Related Questions

#include <list> #include <boost/tuple/tuple.hpp> template<class InputIterator> void f(InputIterator it) { typedef boost::tuple<typename InputIterator::value_type, int>
Say want to store the following: typedef std::function<void(int)> MyFunctionDecl; ..in a collection: typedef std::vector<MyFunctionDecl>
Due to std::sort on a std::list , I receive the following errors: line 44
Test.h #ifndef TEST_H #define TEST_H #include <memory> template <class Type> bool operator==(const std::weak_ptr<Type>& wp1,
I have gotten the following errors using ruby 1.9.2-p320 with Heroku's Taps-using 'db' commands
I was installing a script and got the following errors Warning: include() [function.include]: Unable
Gotw 80 includes the following example: // Example 1 // #include <string> using namespace
Consider the following code: #include <vector> struct A { explicit A(int i_) : i(i_)
I wrote the following simple CUDA kernel: __global__ void pr_kernel(float* O, const float* I,
I get an I/O Error 1784 due to blockwrite in the following code which

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.