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

  • Home
  • SEARCH
  • 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 6553251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:33:34+00:00 2026-05-25T12:33:34+00:00

I have a class Node. This class can add or remove other nodes relative

  • 0

I have a class Node. This class can add or remove other nodes relative to itself. Node is used by a List class. To prevent the nodes being modified directly (externally, IE not by the appropriate classes) during usage and causing problems with the List class, the nodes add/remove functions are either protected or private. This requires that List class is a friend to Node.

However, the problem with this is that the List class itself is a template class for other subclasses, and adding prototyping/adding the friend keyword for each subclass is clearly not the best solution.

How would I design the Node and List class/subclasses so that:

  • Node cannot be constructed by itself externally, is only constructed with specific classes/subclasses?
  • Node can construct/remove other nodes given above?
  • Node functions are only accessible to specific classes (List, list subclasses, and list helper classes – list helper classes are not subclasses of list)?
  • The node variable (Item) is publicly accessible give above?
  • List, list subclasses and list helper classes can directly modify or indirectly modify the non-public variables of Node?

Are these possible, and if so, how?

  • 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-05-25T12:33:35+00:00Added an answer on May 25, 2026 at 12:33 pm

    I would make Node a protected nested class of List:

    class List
    {
        ...
        protected:
            class Node
            {
                ...
            };
    };
    

    This way, only List and its subclasses can access it. Since it is nested within List, list may access its private/protected members and functions. It also helps to highlight the functional relationship between the two classes. This probably takes care of all your dot points except the third.

    EDIT double checking my facts, it seems that in C++ enclosing classes do not have special access permissions to nested class members after all (seems that’s a Java thing), see here. As such, you will need to make Node members public, but I still think this solution encourages good encapsulation.

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

Sidebar

Related Questions

I have a base class Node which contains a list of child nodes. Node
I have this class: public class Source extends Node { protected DistributionSampler delay ;
I have this very simple C++ class: class Tree { public: Node *head; };
I have class method that returns a list of employees that I can iterate
Im having a problem with python.. I have a binary tree node type: class
I have a binary tree class that is created with a root node and
I have this table where I can generate dynamic rows (which has input <type=text
using C# I have a class which contains among other meta information the root
I keep getting this error - error C2819: type 'List' does not have an
I am implementing a sorted list using linked lists. My node class looks like

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.