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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:58:00+00:00 2026-06-14T07:58:00+00:00

I am having difficulty understanding why I am getting this error. I am referring

  • 0

I am having difficulty understanding why I am getting this error. I am referring to both Josuttis’ STL book and other resources and it seems that the way I have declared my iterator below should work:

#ifndef LRU_H
#define LRU_H

#include <queue>
#include <iterator>


class LRU
{
public:

   LRU();                           // default constructor
   LRU(int);                        // constructor with argument
   ~LRU();                          // destructor 

   // Methods
   //
   void enqueue(int);               // add datum to the queue
   void dequeue();                  // remove datum from the queue
   void replace();                  // replacement algorithm
   void displayQueue() const;       // display contents of queue

private:

   // Member Data
   //
   const int MAX_SIZE;
   int m_currentCount;

   std::queue<int> m_buffer;
   std::queue<int>::const_iterator iter;

};

#endif

But the line where I declare my const_iterator generates the following compiler error:

In file included from main.cpp:10:
lru.h:41: error: 'const_iterator' in class 'std::queue<int, std::deque<int, std::allocator<int> > >' does not name a type
In file included from lru.cpp:10:
lru.h:41: error: 'const_iterator' in class 'std::queue<int, std::deque<int, std::allocator<int> > >' does not name a type
lru.cpp: In constructor 'LRU::LRU()':
lru.cpp:17: error: class 'LRU' does not have any field named 'm_pos'
lru.cpp: In constructor 'LRU::LRU(int)':
lru.cpp:23: error: class 'LRU' does not have any field named 'm_pos'

Compilation exited abnormally with code 1 at Thu Nov 15 10:47:31

Is there something special about declaring an iterator in a class that results in the error?

  • 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-14T07:58:01+00:00Added an answer on June 14, 2026 at 7:58 am

    The container adapter std::queue has no publicly accessible iterators. Since the std::queue<int> is hidden in the LRU implementation, you could consider using an std::deque<int> instead. std::deque is the default container used by std::queue under the hood, so you would incur no performance penalty by using it. I think it is safe to use it as long as you do not make the non-queue operations public in your LRU interface.

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

Sidebar

Related Questions

I'm having difficulty understanding this: It is well known that assignment operator won't be
I'm having difficulty understanding variable shadowing in JavaScript based on scopes. Consider this small
This is from apple blocks docs and I am having difficulty understanding this please
I'm having difficulty in understanding what it is that the gtk.notebook_set_window_creation_hook_function is looking for
I'm reading this book: http://eloquentjavascript.net/ which I think is brilliant. However I'm having difficulty
i'm having a hard time understanding custom events and I keep getting this same
I'm following a tutorial on php, and am having difficulty getting this to work.
I was given this starter code for a project, but am having difficulty understanding
I've having difficulty understanding why 40585 is the greatest factorion that exists. Why can
I am having difficulty understanding the part value : value == 0 ? How

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.