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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:37:51+00:00 2026-05-20T04:37:51+00:00

When I put all the source in one file, the program successfully builds. However

  • 0

When I put all the source in one file, the program successfully builds. However when I split them into header files, I get a link error.

The main of my program:
//C++_Class_Templates.cpp

#include <iostream>
#include <vector>
#include "Queue.h"

using namespace std;

//Usage for C++ class templates
void main()
{
     MyQueue<int> q;
     q.Add(1);
     q.Add(2);
}

The Queue.h looks like this

#pragma once
#include <vector>

template <typename T>
class MyQueue
{
     std::vector<T> data; 
   public:
     void Add(T const &);
     void Remove();
     void Print();

};

and the Queue.cpp looks like this:

#include "Queue.h"

template <typename T> void MyQueue<T> ::Add(T const &d)
{
     data.push_back(d);
}

When I try to build it, I get this error:

 1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall
 MyQueue<int>::Add(int const &)" (?Add@?$MyQueue@H@@QAEXABH@Z) referenced in function _main
  • 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-20T04:37:52+00:00Added an answer on May 20, 2026 at 4:37 am

    The short answer is: “you don’t.”

    The longer answer is: well, it’s basically the same as the short answer. For more information, see the C++ FAQ Lite entry “Why can’t I separate the definition of my templates class from its declaration and put it inside a .cpp file?” Except for certain limited-use scenarios (like when you have a small set of known arguments with which you will use the template and you can explicitly instantiate it with those types), the definition of the template must be available when you try to use it.

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

Sidebar

Related Questions

I've always backed up all my source codes into .zip files and put it
So I need to put all the names in a file into column 1
I would like to know how to put all of my ListView rows into
When we started, we put all icons inside a folder in source control, and
What is the best practice for C what you put into a C header
Why am I getting the above compilation error in all of my source files
How would one go best about checking for existence of all files before building?
In all the examples (leaderboard, wordplay, etc.) they have one single HTML template file.
We put all of our unit tests in their own projects. We find that
I put all my code in NS, similar to how jQuery is structured. 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.