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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:53:29+00:00 2026-06-12T23:53:29+00:00

I am trying to use a template class and when I compile it in

  • 0

I am trying to use a template class and when I compile it in one file in LWS it works:

(Link is dead)
~http://liveworkspace.org/code/a9c412a7e683439dfa35a9363749369d~

But when I try to compile it made-up of 3 files,

stack.h lines 4 to 21

stack.cpp lines 24 to 48

main.cpp lines 49 to end

When I try to compile those 3 files I get

Undefined symbols for architecture x86_64:
  "Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::push(Node**, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
      _main in ccCoizCT.o
  "Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::top(Node*&)", referenced from:
      _main in ccCoizCT.o
  "Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::pop(Node*&)", referenced from:
      _main in ccCoizCT.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

Yes I have included stack.h in a stack.cpp and main.cpp files

  • 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-12T23:53:30+00:00Added an answer on June 12, 2026 at 11:53 pm

    Sounds like you need to place the template definitions of stack back in the header file. Templates form a plan for code generation, so if the compiler can’t see the entire template definition and only sees the declaration, code for that specific instantiations of the template will not be generated. It will simply trust the declaration and expect that at link time there exists an objects file with the instantiations of those templates. The solution to this is 1) keep the template definitions in the header file or 2) pre-generate the required definitions so the linker can find them at link time.

    See here:
    Template issue causes linker error (C++)

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

Sidebar

Related Questions

I'm trying to use an instant of a custom class as a template parameter.
This is the provided function template I'm trying to use: template <class Process, class
I'm trying to use the C++ standard library's find algorithm like this: template<class T>
I'm trying to compile simple example to use the boost concept_check Code is as
I'm trying to use G++ to compile some C++ code. It seems to work
I'm going a little nuts trying to figure out how to use template inheritance
I'm trying to use coffeekup as my default template app.set 'view engine', 'coffee' app.register
I'm trying to use PGK.Extensions in a T4 template in VS2008 for VB.NET and
I'm trying to use PDO in this way and reuse the output template: selected_products_show
I'm trying to write a custom rendering template for use in the DisplayForm of

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.