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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:50:20+00:00 2026-05-27T06:50:20+00:00

Do classes have external linkage? If so, why couldn’t I get the following to

  • 0

Do classes have external linkage? If so, why couldn’t I get the following to work on gcc?

// mycpp1.cpp

class MyClass
{
    int x;
    // ......
};

`

// mycpp2.cpp

class MyClass; // why doesn't this work?

I’ve done some googling around and came around this,

C++ Standard

(3.5/4) a named class (clause 9), or an unnamed class defined in a
typedef declaration in which the class has the typedef name for
linkage purposes (7.1.3);

I could just include the file, but what would be the purpose of linkage?

  • 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-27T06:50:21+00:00Added an answer on May 27, 2026 at 6:50 am

    Why I half agree with Nawez that you shouldn’t worry too much about
    linkage, it is nice to understand it, so you know why the coding pattern
    you’re using works (and why other patterns don’t). Linkage defines how
    a name (a symbol) is bound to an entity (variable, function, type,
    etc.). External linkage means that the name (or the qualified version
    of it) binds to the same entity in all of the translation units: in your
    case, that MyClass is the same class in all of the translation units.
    It doesn’t mean that all translation units automatically know how it is
    defined; just that MyClass in mycpp1.cpp is the same type as
    MyClass in mycpp2.cpp. For various reasons related to compiler and
    linker technology, you still have to provide a definition in every source
    (preferably by means of an include) that uses it, but these definitions
    are required to be identical (which is why the include is preferred),
    because the compiler will generate code treating them as identical.

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

Sidebar

Related Questions

I have two classes: public class TestClass1 { public int TestInt { get; set;
I have classes like these: class MyDate { int year, month, day; } class
D2.0 classes have a __monitor class property that gives access to the class object's
I have classes that store data, and methods to go get data for individual
I have two classes, one inherited from the other. When I compile, I get
I have a form and several external classes (serial port, file access) that are
I have a class from an external library that I want to extend with
I have 2 classes within same package. Both classes have main method in them.
Some of my classes have final fields that are populated from the constructor as
Both the MySQLi and MySQLi_STMT classes have an $insert_id property. If I am connected

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.