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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:44:52+00:00 2026-05-31T09:44:52+00:00

First I want to make it clear that this is a homework based question.

  • 0

First I want to make it clear that this is a homework based question. That being the case, I want to ‘understand’ where my thinking is going haywire and not just have an answer given 😉

I have a class called RegistrationList that is derived from QList like such:

class RegistrationList : public QList<Registration *>

The Registration object has two children classes so the list RegistrationList have pointers to objects of the original Registration class as well as its two children:

class GuestRegistration : public Registration

and

class StudentRegistration : public Registration

the class RegistrationList must have a function prototyped like this:

 void displayList();

What this function needs to do is call a function called

QString toString();

in all the objects in the list.

Now this is what I have for the implementation of the

 void displayList();

member function of RegistrationList class:

void RegistrationList::displayList()
{
    QTextStream cout(stdout);
    cout << "\nHere follows a list of all registrations:";
    cout << "\n=========================================\n";

    foreach(Registration *r, this) { r->toString(); }
}

But the compiler doesn’t like it at all. The way I see this is that I want to iterate over a list containing a collection of Registration like objects. Each of these objects have a member function called

toString();  

to print out pretty formatted info. This works 100%. If I comment out the foreach line the code compiles with no issues. The only thing I can think of is that foreach doesn’t like to have

this

as its second parameter.

It is not a must that I have to use foreach but it will bug me to no end if I cannot find out why it doesn’t work although it ‘seems’ as if it should…

  • 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-31T09:44:53+00:00Added an answer on May 31, 2026 at 9:44 am

    foreach requires the second argument to be a reference to an object. You therefore need to dereference this:

    foreach(Registration *r, *this) { r->toString(); }
    

    You also probably want to write r->toString(); to the stream you have just created.

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

Sidebar

Related Questions

First of all, I want to make myself clear that I do understand that
Let's imagine I want to make a templated function that returns the first element
This one has me kind of stumped. I want to make the first word
First of all, I don't want to use a join because that will make
Before I begin I want to make it clear that I don't want the
Ok my first question was not clear so i m sorry about that. For
First off, let me say that this is not homework (I am an A-Level
I want to make sure the first 4 letters in a eight character code
say I want to make the first row of the excel ss something like
i want to make a draggable image in jquery. first of all my experience

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.