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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:17:10+00:00 2026-05-11T02:17:10+00:00

When I write C++ code for a class using templates and split the code

  • 0

When I write C++ code for a class using templates and split the code between a source (CPP) file and a header (H) file, I get a whole lot of ‘unresolved external symbol’ errors when it comes to linking the final executible, despite the object file being correctly built and included in the linking. What’s happening here, and how can I fix it?

  • 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. 2026-05-11T02:17:11+00:00Added an answer on May 11, 2026 at 2:17 am

    Templated classes and functions are not instantiated until they are used, typically in a separate .cpp file (e.g. the program source). When the template is used, the compiler needs the full code for that function to be able to build the correct function with the appropriate type. However, in this case the code for that function is detailed in the template’s source file and hence unavailable.

    As a result of all this the compiler just assumes that it’s defined elsewhere and only inserts the call to the templated function. When it comes to compile the template’s source file, the specific template type that is being used in the program source isn’t used there so it still won’t generate the code required for the function. This results in the unresolved external symbol.

    The solutions available for this are to:

    1. include the full definition of the member function in the template’s header file and not have a source file for the template,
    2. define all the member functions in the template’s source file as ‘inline’ (Update: [this does not work on Visual Studio 2017+]), or
    3. define the member functions in the template’s source with the ‘export’ keyword. Unfortunately this isn’t supported by a lot of compilers. (Update: this has been removed from the standard as of C++11.)

    Both 1 and 2 basically address the problem by giving the compiler access to the full code for the templated function when it is attempting to build the typed function in the program source.

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

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There is a pretty thorough explanation of what thunk means… May 11, 2026 at 10:20 am
  • added an answer According to RFC 4288 "Media Type Specifications and Registration Procedures",… May 11, 2026 at 10:20 am
  • added an answer Here is a macro that will do it: Imports System… May 11, 2026 at 10:20 am

Related Questions

When I write C++ code for a class using templates and split the code
When I write code like this in VS 2008: .h struct Patterns { string
When I write a class I always expose private fields through a public property
When I write an app, I use the System.Data interfaces (IDbConnection, IDbCommand, IDataReader, IDbDataParameter,
I have a textbox and a link button. When I write some text, select
How does Python's slice notation work? That is: when I write code like a[x:y:z]
When I'm joining three or more tables together by a common column, I'd write
When I retrieve any Scalar value from the database, I usually write code like
I wish to write a windows app which does something when I become disconnected
I want to write an Exception to an MS Message Queue. When I attempt

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.