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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:59:02+00:00 2026-06-03T16:59:02+00:00

Possible Duplicate: Why can templates only be implemented in the header file? “Undefined symbols”

  • 0

Possible Duplicate:
Why can templates only be implemented in the header file?
“Undefined symbols” linker error with simple template class

queue.h

#include<iostream>
using namespace std;

template <class t>
class queue {  

    public:  
        queue(int=10);  
        void push(t&);  
        void pop();  
        bool empty();    

    private:  
        int maxqueue;  
        int emptyqueue;  
        int top;  
        t* item;  
};  

queue.cpp

#include<iostream>

#include"queue.h"
using namespace std;

template <class t>
queue<t>::queue(int a){
    maxqueue=a>0?a:10;
    emptyqueue=-1;
    item=new t[a];
    top=0;
}

template <class t>
void queue<t>::push(t &deger){

    if(empty()){
        item[top]=deger;
        top++;
    }
    else
        cout<<"queue is full";
}
template<class t>
void queue<t>::pop(){
    for(int i=0;i<maxqueue-1;i++){
        item[i]=item[i+1];
    }
    top--;
    if(top=emptyqueue)
        cout<<"queue is empty";
}
template<class t>
bool queue<t>::empty(){
    if((top+1)==maxqueue)
        return false
    else
        return true 
}

main.cpp

#include<iostream>
#include<conio.h>

#include"queue.h"
using namespace std;

void main(){
    queue<int>intqueue(5);
    int x=4;
    intqueue.push(x);

    getch();
}

I have created queue using template. Compiler gave this errors. I couldn’t solve this problem.

1>main.obj : error LNK2019: unresolved external symbol “public: void __thiscall queue::push(int)” (?push@?$queue@H@@QAEXH@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol “public: __thiscall queue::queue(int)” (??0?$queue@H@@QAE@H@Z) referenced in function _main
1>c:\users\pc\documents\visual studio 2010\Projects\lab10\Debug\lab10.exe : fatal error LNK1120: 2 unresolved externals

EDIT: Solution is given in here.

  • 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-03T16:59:03+00:00Added an answer on June 3, 2026 at 4:59 pm

    Put all the template related queue implementation in the header file. Just like: Why can templates only be implemented in the header file?

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

Sidebar

Related Questions

Possible Duplicate: Why can templates only be implemented in the header file? Undefined reference
Possible Duplicate: Why can templates only be implemented in the header file? Why should
Possible Duplicate: Why can templates only be implemented in the header file? When I
Possible Duplicate: Why can templates only be implemented in the header file? Why should
Possible Duplicate: Why can templates only be implemented in the header file? Why should
Possible Duplicate: Why can templates only be implemented in the header file? I got
Possible Duplicate: Why can templates only be implemented in the header file? I've been
Possible Duplicate: Why can templates only be implemented in the header file? I've struggled
Possible Duplicate: Why can templates only be implemented in the header file? hello everyone
Possible Duplicates: Templated function being reported as “undefined reference” during compilation Why can templates

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.