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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:22:02+00:00 2026-06-05T07:22:02+00:00

My goal is to create a linked list with nodes of different types. For

  • 0

My goal is to create a linked list with nodes of different types. For this, I created a node class template as follows:

template <class T>
class N_Node
{
public:
    N_Node(T e, N_Node *p = nullptr ,N_Node *n = nullptr);
    void set_previous(N_Node<T> *p);
    void set_next(N_Node<T> *n);
    N_Node get_previous();
    N_Node get_next();

    T element;
    N_Node *prev;
    N_Node *next;
};

Now, in the main.cpp, when i try to do the following, it gives me an error saying argument of type N_Node<int>* is incompatible with parameter of type N_Node<char>*. So, I was wondering if there is any way to specify that the node set as the previous can be of a different type to the current node?

N_Node<int> n1(5);
N_Node<char> n3('g');
n3.set_previous(&n1);
  • 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-05T07:22:03+00:00Added an answer on June 5, 2026 at 7:22 am

    Absolutely, create a N_Node_Base class that omits the element member, and inherit from it for N_Node<T>. Most C++ standard library implementations do this to reduce template overhead.

    Of course, by doing this you’ll lose the ability to traverse the list and access elements because you won’t know the type of each element. You might want to type-erase past a minimal interface for T using e.g. boost::any, but you’ll have to say more about why you want to do this.

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

Sidebar

Related Questions

My goal is to create a list from menu.bin. This is the func: pitem
I have a linked list of Nodes, each Node is defined as: struct Node
The goal is to create a mock class which behaves like a db resultset.
This follows my previous question about TFS 2010 and the possibility to create a
I have two content types (job_post and application) linked using the node reference +
My goal is to create a time zone converter that will compare two different
Goal: to create a percentage column based off the values of calculated columns. Here's
Duplicate: PHP validation/regex for URL My goal is create a PHP regex for website
I am very new to Json and my goal to create the Json output
My goal is to create a canned email on my server and then send

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.