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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:59:52+00:00 2026-05-18T02:59:52+00:00

Several lines of code are worth a thousand words: I have three simple files:

  • 0

Several lines of code are worth a thousand words:

I have three simple files: header.h, main.cpp, other.cpp

// header.h

  #pragma once

inline const int& GetConst()
{
    static int n = 0;
    return n;
}

const int& r = GetConst();

// main.cpp

  #include "header.h"

int main()
{
    return 0;
}

// other.cpp

  #include "header.h"

When compiling the simplest project, the VC++ 2010 complains as follows:

ClCompile:
  other.cpp
  main.cpp
  Generating Code...
  other.obj : error LNK2005: "int const & const r" (?r@@3ABHB) already defined in main.obj
D:\Test\Debug\bug.exe : fatal error LNK1169: one or more multiply defined symbols found

Build FAILED.

Time Elapsed 00:00:00.29
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I am sure this is a bug of VC++ 2010, because of the following two references:

1, The C++ standard says: (at page 140 of n3126)

“Objects declared const and not explicitly declared extern have internal linkage.”

2, The MSDN says: (at: http://msdn.microsoft.com/en-us/library/357syhfh(VS.80).aspx)

“In C, constant values default to external linkage, so they can appear only in source files. In C++, constant values default to internal linkage, which allows them to appear in header files.

The const keyword can also be used in pointer declarations.”

  • 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-18T02:59:52+00:00Added an answer on May 18, 2026 at 2:59 am

    The paragraph you cite from the C++ Standard reads (C++03 7.1.1/6):

    Objects declared const and not explicitly declared extern have internal linkage.

    You have not declared an object. You have declared a reference. A reference is not an object. That said, 3.5/3 says:

    A name having namespace scope has internal linkage if it is the name of an object or reference that is explicitly declared const and neither explicitly declared extern nor previously declared to have external linkage

    However, 8.3.2/1 says:

    Cv-qualified references are ill-formed

    So, while a const-qualified reference would have internal linkage, it’s not possible to const-qualify a reference.

    The reference in your sample program is not const-qualified, it’s a reference to a const-qualified int.

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

Sidebar

Related Questions

Several lines of code are worth a thousand words: I have three simple files:
Hopefully a picture is worth a thousand lines of code because I don't want
Let's say I have several lines of code to clarify specific settings on a
Possible Duplicate: iif equivalent in c# I have several lines of code using IIf
/** Constant <code>IDX_USER=IDX_+ USER_ID</code> */ I have several lines of code which was generated
I have a string with several lines of CSS code. I want to match
I have several files containing this line Release: X I want to increment X
I have a ~23000 line SQL dump containing several databases worth of data. I
I have several log files of events (one event per line). The logs can
In our code base there are a few very long methods (several pages worth

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.