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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:53:30+00:00 2026-06-17T00:53:30+00:00

Possible Duplicate: Difference between const declarations in C++ #include <iostream> class Bar{}; void foo(const

  • 0

Possible Duplicate:
Difference between const declarations in C++

#include <iostream>

class Bar{};

void foo(const Bar x){}  //l5
void foo(Bar x){}        //l6
void foo(Bar const x){}  //l7

////pointer functions

void foo(const Bar* x){} //l11
void foo(Bar* x){}       //l12
void foo(Bar* const x){} //l13

Compiler output: (long story short l5,l6,l7 conflict; but only l12,l13 conflict)

untitled.cpp:6:6: error: redefinition of ‘void foo(Bar)’
untitled.cpp:5:6: error: ‘void foo(Bar)’ previously defined here
untitled.cpp:7:6: error: redefinition of ‘void foo(Bar)’
untitled.cpp:5:6: error: ‘void foo(Bar)’ previously defined here
untitled.cpp:13:6: error: redefinition of ‘void foo(Bar*)’
untitled.cpp:12:6: error: ‘void foo(Bar*)’ previously defined here

What going on?

  1. What is the meaning of each of the declarations
  2. Why does all 3 declarations conflict with object functions but only 2 with pointer functions?
  3. Please elaborate that conflict is between l12 and l13, even though l12 does not contain const keyword
  4. Really sorry if trivial question
  • 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-17T00:53:31+00:00Added an answer on June 17, 2026 at 12:53 am

    The “problem” is that constness of a parameter’s value doesn’t participate in overloading!

    First, Bar const and const Bar are already identical meaning, so they would automatically have a problem. But as a function parameter the const doesn’t apply to overloading so the Bar version of the function also looks the same too. The const in the paremeter only tells the compiler that you don’t intend to modify it in the function body.

    For the same reason, Bar* and Bar* const are treated the same: The const applies to the value of the parameter (not what’s pointed to) and does not participate in overloading, so you’ve defined the same function.

    On the other hand const Bar* means something totally different: A non-const pointer to a const object (of type Bar). Since the type is different it does participate in overloading and allows that function to be unique.

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

Sidebar

Related Questions

Possible Duplicate: What is the difference between const and readonly? i have doubt in
Possible Duplicate: Difference between Color.red and Color.RED I have seen that the Java class
Possible Duplicate: Difference between pointer variable and reference variable in C++ When should I
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading
Possible Duplicate: Difference between void main and int main? Why is void main() {
Possible Duplicate: what is the difference between const int*, const int * const, int
Possible Duplicate: What is the difference between const and readonly? are these interchangeable? can
Possible Duplicate: what is the difference between const int*, const int * const, int
Possible Duplicate: what is the difference between const int*, const int * const, int
Possible Duplicate: What is the difference between const and readonly? So from what I

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.