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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:59:25+00:00 2026-06-11T17:59:25+00:00

I am working on a stack class and have two constructors. One of interest

  • 0

I am working on a stack class and have two constructors. One of interest is this one.

template <typename T>
stack<T>::stack( const int n)
{
 capacity = n ;
 size = 0 ;
 arr = new T [capacity] ;
}

I am calling it inside main like this.

stack<int> s1(3) ;

The program compiles fine but i get this run time error.

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall
 stack<int>::~stack<int>(void)" (??1?$stack@H@@QAE@XZ) referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall    
stack<int>::stack<int>(int)" (??0?$stack@H@@QAE@H@Z) referenced in function _main

1>D:\\Microsoft Visual Studio 10.0\Visual Studio 2010\Projects\Expression
 Evaluation\Debug\Expression Evaluation.exe : fatal error LNK1120: 2 unresolved externals

I am working on Microsoft visual studio 2010 and this problem is taking me nowhere.
Any hint would be appreciated.

  • 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-11T17:59:26+00:00Added an answer on June 11, 2026 at 5:59 pm

    It’s not a runtime error, it’s a linker error. The problem is probably that the implementations of the constructor and the destructor are in a source file. With template classes, you have to place the implementations of all the methods in the header (or in the source file that uses them, but that’s equivalent to putting them in the header).

    So basically do this:

    template<class T>
    class stack
    {
    public:
        stack( const int n)
        {
            capacity = n ;
            size = 0 ;
            arr = new T [capacity] ;
        }
    
        // and the same for all other method implementations
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a weird one. On and off as I have been working on
I have two tables, for simplicity lets pretend they're defined like this Stack {
Background I am working with a monad built of a stack of transformers one
Found This: tyty stack, Social Icons not working with Infinite Scrolling on Wordpress I'm
I am working on a Polynomial class which uses the STL linked list. One
I have researched a lot on how to get this working but I couldn't
I have the Parent Class : class clsTestParent { protected int x; public void
I am working on a simple protocol stack for a small embedded system (multidrop,
I am working on an embedded TCP/IP4 stack and HTTP/SNMP/SMTP stuff. It functionally works
Working on the N-queens problem. Having some difficult filling up the stack correctly. Was

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.