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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:50:06+00:00 2026-06-18T03:50:06+00:00

I’m more of a hardware person, but the chip design tools I’m using require

  • 0

I’m more of a hardware person, but the chip design tools I’m using require me to write some C++ code. I am not familiar with object-oriented programming; although I have a good handle on C. What I’m asking is for an explanation of how to structure my class (called cq) to accomplish the task at hand.

I would like to be able to generate a queue of a specified data type and specified size (which should not change after being generated). Ideally, this would be accomplished like this…

my_queue = new cq(uint8_t, 6);

…which would generate an array (or vector) of six 8-bit unsigned integers.

Then, I would like a method to both insert an element to an end and return the element at the head of the queue as follows.

uint8_t front;
front = my_queue.advance(28);

What kind of structure do I need to accomplish this? Do I need a template since the data types are variable? Or should I have a generic class and have a class for each data type inherit its structure?

Thank you!

Edit: using input from the answers below, I’ve come up with the following:

template <class type>
template <class size>
class CQ {

    private:
        // Allocates a queue with type and size
        // specified by template arguments.
        std::queue<type> cycle_queue(size, 0);

    public:
        // Inserts input to the end of the queue;
        // removes and returns the front element.
        type advance(type in){
            type out = cycle_queue.front();
            cycle_queue.push_back(in);
            cycle_queue.pop_front();
            return out;
        }

}

My question then becomes… how do I instantiate this in my main C++ program? I tried this, but it did not work:

CQ<uint8_t><6> my_queue;
my_queue.advance(28);

Thanks again!

  • 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-18T03:50:08+00:00Added an answer on June 18, 2026 at 3:50 am

    This looks like a perfect application for STL containers. You could write your own queue class (as a template class, since you want to be able to specify data type), but why re-invent the wheel?

    You’re looking probably for: std::list, for a FIFO queue. For your particular example:

    std::list<uint8_t> my_queue;
    my_queue.push_back(28);            // push an element
    uint8_t front = my_queue.front();  // get the element on the front of the queue
    my_queue.pop_front();              // and then pop it
    

    If you’re not already somewhat familiar with OOP and C++, writing your own template classes might be a bit out of reach for now. There are good references all over the ‘net though if you want to try: e.g. http://www.cplusplus.com/doc/tutorial/templates/

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into

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.