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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:45:19+00:00 2026-06-10T04:45:19+00:00

Okay so I have a class, LinkedList, with a nested class, LinkedListIterator. Within LinkedListIterator’s

  • 0

Okay so I have a class, LinkedList, with a nested class, LinkedListIterator. Within LinkedListIterator’s methods I reference the private fields of LinkedList. Which I thought was legal. But I get the error:

from this location

every time I reference them.

And I get corresponding error messages on the fields in the enclosing class:

invalid use of non-static data member 'LinkedList<int>::tail'

Any idea why? The relevant code is below:

template<class T>
class LinkedList {

    private:
        //Data Fields-----------------//
        /*
         * The head of the list, sentinel node, empty.
         */
        Node<T>* head;
        /*
         * The tail end of the list, sentinel node, empty.
         */
        Node<T>* tail;
        /*
         * Number of elements in the LinkedList.
         */
        int size;

    class LinkedListIterator: public Iterator<T> {

            bool add(T element) {

                //If the iterator is not pointing at the tail node.
                if(current != tail) {

                    Node<T>* newNode = new Node<T>(element);
                    current->join(newNode->join(current->split()));

                    //Move current to the newly inserted node so that
                        //on the next call to next() the node after the
                        //newly inserted one becomes the current target of
                        //the iterator.
                    current = current->next;

                    size++;

                    return true;
                }

                return false;
            }
  • 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-10T04:45:20+00:00Added an answer on June 10, 2026 at 4:45 am

    You can’t just use non-static members like that. I think the following example will clear things out:

    LinkedList<int>::LinkedListIterator it;
    it.add(1);
    

    What would current and tail be inside the method? There’s no instance of LinkedList to speak of, so those members don’t even exist yet.

    I’m not saying make the members static, that would be wrong, but re-think your approach.

    Look into how std iterators are.

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

Sidebar

Related Questions

Okay I have a series of objects based on a base class which are
Okay, I have something like this in C++: class MyClass{ private: int someVariable; int
Okay, let's say we have a class defined like public class TestClass { private
I have a class which contains a BYTE* , a reference counter and a
Okay so let's say I have class A... CLASS A has a method that
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
Okay so I have started a new language in class. We are learning Scheme
Okay, newbie multi-threading question: I have a Singleton class. The class has a Static
Okay, so i have this code i wrote: class Connection { public static StreamWriter
Okay so, I have this project structure: package A.B class SuperClass (this class is

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.