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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:10:33+00:00 2026-05-23T08:10:33+00:00

I am getting the following when trying to compile the code below: preallocarray.h: In

  • 0

I am getting the following when trying to compile the code below:

preallocarray.h: In member function 'void PreallocArray<T>::push_back(const T&)':
preallocarray.h:82: error: expected `;' before 'itr'

I have a nested const_iterator class inside of my LinkedList class I created. It’s been many years since I’ve done C++, so this is probably caused by something silly, but I’ve been hacking around and googling for an hour with no luck…

Here’s my linked list class definition, decared in linklist.h:

template <typename T> 
class LinkedList 
{
    <snip...>
    public:
        class const_iterator
        {
        <snip...>
        };
    <snip...>
};

Then I have a second class, declared in preallocarray.h, as follows:

#include "linklist.h"
template <typename T>
class PreallocArray
{
    <snip...>
    public:
        void push_back( const T & newValue )
        {
            if (capacity == size)
            {
                allocateNode( capacity / 2 );
            }
            LinkedList<Node>::const_iterator itr; // error occurs here
            theList.end();
        }
    <snip...>

    private:
        LinkedList<Node> theList; // the linked list of nodes
    <snip...>
};
  • 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-23T08:10:33+00:00Added an answer on May 23, 2026 at 8:10 am
    LinkedList<Node>::const_iterator itr; // error occurs here
    

    Based on the fact the enclosing class is actually a class template, I suspect that you intended to write T instead of Node. What is Node by the way? And where is it defined?

    If you really wanted to write T, then you’ve to write it as:

    typename LinkedList<T>::const_iterator itr; 
    

    Don’t forget to write typename as I’ve written above. If you’ve to write typename even if the template parameter is Node but its definition depends on T in some way:

    typename LinkedList<Node>::const_iterator itr;//if Node depends on T
    

    To know why typename is needed, see this answer by @Johannes Schaub:

    • Where and why do I have to put the "template" and "typename" keywords?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the following error when trying to compile OpenSSL 1.0, 64 bit: ias
I'm getting the following error when trying to run a JSP. I'm using Tomcat
I'm getting the following error when trying to build my app using Team Foundation
I am getting the following error when trying to install Visual Studio 2005 on
I am trying to compile following code in C#: String[] words = {Hello, Worlds};
I am trying to compile the following very very simple piece of source code:
I'm trying to compile the following code under VC2010. struct CircValRange { double a,b;
I'm getting following linker error when I compile my program with VS2008 solution which
I'm getting the following error when trying to build my very simple webservice project.
Hey everyone, I am trying to run the following program, but am getting a

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.