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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:12:08+00:00 2026-06-12T13:12:08+00:00

I hope this hasn’t been covered in some question before. I looked as best

  • 0

I hope this hasn’t been covered in some question before. I looked as best I could, but I think part of the problem in the first place is that I don’t understand what is up, and that may have prevented me from finding a previous answer. My apologies if so, but otherwise…

For practice with templates and generally understanding C++ and code design better, I’ve set to writing a (currently quite simple) implementation of a linked list, mostly seeking to mimic std::list. I’ve been working at implementing iterators properly, and the other components logically, but I’ve run into a snag. I’d guess it is with template syntax somewhere, but I’m not sure. It could be just some silly mistake.

Here’s the general structure of the class:

template <class T>
class LinkedList {
public:
    LinkedList();
    class Iterator;
    void push_front(const T&);
    void push_back(const T&);
    void pop_front();
    void pop_back();
    T& front();
    T& back();
    unsigned int size() const;
    bool empty() const;
    Iterator begin();
    Iterator end();
private:
    struct ListNode;
    ListNode* m_front;
    ListNode* m_back;
    unsigned int m_size;
};

template <class T>
class LinkedList<T>::Iterator {
public:
    Iterator();
    Iterator(const Iterator& rhs);
    Iterator(ListNode* const& node);
    Iterator operator=(const Iterator& rhs);
    T& operator*();
    bool operator==(const Iterator& rhs) const;
    bool operator!=(const Iterator& rhs) const;
    Iterator operator++();
private:
    ListNode* m_node;
};

template <class T>
struct LinkedList<T>::ListNode {
    T* m_data;
    ListNode* m_next;
};

And here is the offending function:

template <class T>
void LinkedList<T>::push_front(const T&) {
    if (m_front == NULL) {
        m_front = new ListNode;
        *(m_front->m_data) = T;
        m_front->m_next = NULL;
        m_back = m_front;
    } else if (m_front == m_back) {
        m_front = new ListNode;
        *(m_front->m_data) = T;
        m_front->m_next = m_back;
    } else {
        ListNode* former_front(m_front);
        m_front = new ListNode;
        *(m_front->m_data) = T;
        m_front->m_next = former_front;
    }
}

And the error given by GCC 4.6.3:

linkedlist.hpp: In member function ‘void pract::LinkedList<T>::push_front(const T&)’:
linkedlist.hpp:75:31: error: expected primary-expression before ‘;’ token
linkedlist.hpp:80:31: error: expected primary-expression before ‘;’ token
linkedlist.hpp:85:31: error: expected primary-expression before ‘;’ token

I hope all that helps, but if anything else would be desirable please do ask.
Thanks all.

  • 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-12T13:12:09+00:00Added an answer on June 12, 2026 at 1:12 pm

    The problems is on these lines:

    *(m_front->m_data) = T;
    

    This is attempting to assign a type to a variable, which is clearly not possible. Probably you want a named argument and to use said argument for this assignment:

    template <class T>
    void LinkedList<T>::push_front(const T& t) {
        if (m_front == NULL) {
            m_front = new ListNode;
            *(m_front->m_data) = t;
            m_front->m_next = NULL;
            m_back = m_front;
        } else if (m_front == m_back) {
            m_front = new ListNode;
            *(m_front->m_data) = t;
            m_front->m_next = m_back;
        } else {
            ListNode* former_front(m_front);
            m_front = new ListNode;
            *(m_front->m_data) = t;
            m_front->m_next = former_front;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope that this question hasn't been asked already, but I was looking for
Hope this question hasn't been asked before. I've got the following working <!-- 640x920
I hope this question (or one similar) hasn't been asked before. Sincere apologies if
I hope this hasn't been asked before but it's hard for me to put
I hope this hasn't been asked before. I have a nullable boolean called boolIsAllowed
I hope this hasn't been asked and I just missed it, but I searched
i hope this hasn't already been answered, I've looked through for awhile and haven't
I hope this hasn't already been answered, but I feel like I have read
I hope this hasn't been asked before, if so I apologize. EDIT: For clarity,
I hope this question isn't duplicating something in the archives; I've looked but can't

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.