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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:35:35+00:00 2026-06-01T19:35:35+00:00

I am implementing an Ordered List data structure in C++ using class templates.For simplicity,

  • 0

I am implementing an Ordered List data structure in C++ using class templates.For simplicity, I implemented each constructor and function inline. I made my own Node class for this project.

The compiler error is pasted at the bottom of this question. “undefined reference to `Node::~Node()'”. This is my first time working with templates and I’ve never seen this error before. I have no idea where to begin.
Any help would be appreciated!

Node.h

#ifndef NODE_H
#define NODE_H

#include <iostream>
#include <cstdlib>

template <class E>
class Node {
public:
    Node(const E init_data = NULL, Node<E>* init_link = NULL){data = init_data; link = init_link;}
    Node(const Node<E>& orig){data = orig.getData(); setLink = NULL;}
    virtual ~Node();

    E getData() const{return data;}
    void setData(E newData){data = newData;}

    Node<E>* getLink(){return link;}
    void setLink(Node<E>* nextLink) {link = nextLink;}
private:
    E data;
    Node<E>* link;
};

#endif  /* NODE_H */

MyOrderedList.h

#ifndef MYORDEREDLIST_H
#define MYORDEREDLIST_H

#include <iostream>
#include <cstdlib>
#include "Node.h"

template <class E>
class MyOrderedList;
template <class E>
std::ostream& operator <<(std::ostream& out, const MyOrderedList<E>& list);

template <class E>
class MyOrderedList {
public:
    MyOrderedList()
    {/*IMPLEMENTATION*/}

    MyOrderedList(const MyOrderedList<E>& orig)
    {/*IMPLEMENTATION*/}

    void operator =(const MyOrderedList<E>& orig)
    {/*IMPLEMENTATION*/}

    virtual ~MyOrderedList()
    {/*IMPLEMENTATION*/}

    bool remove(E data)
    {/*IMPLEMENTATION*/}

    MyOrderedList<E> kLargest(int k) const
    {/*IMPLEMENTATION*/}

    E get(int pos) const
    {/*IMPLEMENTATION*/}

    void insert(E data)
    {/*IMPLEMENTATION*/}

    MyOrderedList<E> operator +(const MyOrderedList<E>& list)
    {/*IMPLEMENTATION*/}

    friend std::ostream& operator <<(std::ostream& out, const MyOrderedList<E>& list)
    {/*IMPLEMENTATION*/}

private:
    Node<E>* head;
    int size;
};

#endif  //MYORDEREDLIST_H

main.cpp

#include <cstdlib>
#include <iostream>
#include "MyOrderedList.h"

using namespace std;

int main(int argc, char** argv) 
{
    MyOrderedList<int> list;
    list.insert(5);
    std::cout << list << std::endl;;

    return 0;
}

Compiler Error

g++     -o dist/Debug/Cygwin-Windows/project7_windows build/Debug/Cygwin-Windows/main.o  
build/Debug/Cygwin-Windows/main.o: In function `_ZN4NodeIiE7getLinkEv':
/cygdrive/c/Users/John/Desktop/Dropbox/Data Structures/Project7 Windows/MyOrderedList.h:(.rdata$_ZTV4NodeIiE[vtable for Node<int>]+0x8): undefined reference to `Node<int>::~Node()'
/cygdrive/c/Users/John/Desktop/Dropbox/Data Structures/Project7 Windows/MyOrderedList.h:(.rdata$_ZTV4NodeIiE[vtable for Node<int>]+0xc): undefined reference to `Node<int>::~Node()'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin-Windows/project7_windows.exe] Error 1

make[1]: * [.build-conf] Error 2
make: *
[.build-impl] Error 2

  • 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-01T19:35:37+00:00Added an answer on June 1, 2026 at 7:35 pm

    This

    class Node {
      virtual ~Node(); 
    };
    

    declares (but does not define) a virtual destructor for Node (the templateness does not matter here). You will either need to

    1. delete this line (thus going with the compiler provided default implementation) or
    2. provide an definition as well:

    .

    class Node {
      virtual ~Node() { /* put your dtor logic here */ } 
    };
    

    Do not be affraid to delete the declaration uless you are planning to inherit from Node as you cannot put much logic in Node’s dtor: it does not know much about its template type. Unless you are planning to delete the pointer to the next node (Node::link), which is probably a dangerous proposition

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

Sidebar

Related Questions

How would you go about implementing a priority queue using a linked list in
Currently I am using the following code to print a large data structure print(json.dumps(data,
implementing publishActivity in PHP using the REST API using this code: $activity = array(
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
In addition to implementing a Bag & List for an assignment, the next step
Implementing the basic algorithm using last array as a pivot in Java, is it
When implementing iterator using yield return , is there any difference between returning IEnumerator
Implementing a Thread by providing a new class that extends Thread and overriding its
I´m sure there´s a clever one-liner using the C++ stl generic algorithms for implementing
I am implementing the complex algorithm which part is sorting array of ordered sequences

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.