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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:33:43+00:00 2026-06-01T06:33:43+00:00

Header file: // pe10-8arr.h — header file for a simple list class #ifndef SIMPLEST_

  • 0

Header file:

// pe10-8arr.h -- header file for a simple list class

#ifndef SIMPLEST_
#define SIMPLEST_

// program-specific declarations
const int TSIZE = 45;      // size of array to hold title
struct film
{
    char title[TSIZE];
    int rating;
};

// general type definitions
typedef struct film Item;

const int MAXLIST = 10;
class simplist
{
private:
    Item items[MAXLIST];
    int count;
public:
    simplist(void);
 bool isempty(void);
 bool isfull(void);
    int itemcount();
 bool additem(Item item);
    void transverse( void (*pfun)(Item &item));
};

#endif

Code using header:

#include "pe10-8arr.h"

simplist::simplist(void)
{
    count = 0;
}

bool simplist::isempty(void)
{
    return count == 0;
}

bool simplist::isfull(void)
{
    return count == MAXLIST;
}

int simplist::itemcount()
{
    return count;
}
bool simplist::additem(Item item)
{
    if (count == MAXLIST)
        return false;
    else
        items[count++] = item;
    return true;
}

void simplist::transverse( void (*pfun)(Item &item))
{
    for (int i = 0; i < count; i++)
        (*pfun)(items[i]);
}

#include <iostream>
#include <cstdlib>         // prototype for exit()
#include "pe10-8arr.h"     // simple list class declaration
                                // array version
void showmovies(Item &item); // to be used by transverse()

int main(void)
{
    using namespace std;
    simplist movies;     // creates an empty list
    Item temp;

    if (movies.isfull())    // invokes isfull() member function
    {
        cout << "No more room in list! Bye!\n";
        exit(1);
    }
    cout << "Enter first movie title:\n";
    while (cin.getline(temp.title,TSIZE) && temp.title[0] != '\0')
    {
        cout << "Enter your rating <0-10>: ";
        cin >> temp.rating;
        while(cin.get() != '\n')
            continue;
        if (movies.additem(temp) == false)
        {
            cout << "List already is full!\n";
            break;
        }
        if (movies.isfull())
        {
            cout << "You have filled the list.\n";
            break;
        }
        cout << "Enter next movie title (empty line to stop):\n";
    }
    if (movies.isempty())
        cout << "No data entered. ";
    else
    {
        cout << "Here is the movie list:\n";
        movies.transverse(showmovies);
    }
    cout << "Bye!\n";
    return 0;
}

void showmovies(Item &item)
{
        std::cout << "Movie: " << item.title << "  Rating: "
             << item.rating << std::endl;

}

The code above just compile and run successfully. Can anyone tell me why the function showmovies() can access the item member of simplist using reference without being declared as friend function or member function?

  • 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-01T06:33:44+00:00Added an answer on June 1, 2026 at 6:33 am

    The function is handed an Item object (by reference), it does not know or care where it came from. The caller of the function is the one that actually pulled the object from inside the complete object, but transverse has access by being a member of the class.

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

Sidebar

Related Questions

I have the following header file: #ifndef CLASSES_H #define CLASSES_H class Mouse // Handles
Here's my header file Normal.h: #ifndef NORMAL_H #define NORMAL_H #include Vector3.h class Normal {
in header file I have defined the following function #ifndef OS_H #define OS_H #include
I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //
I have a header file with all the enums listed (#ifndef #define #endif construct
This is my header file: /** * Job.h * **/ #ifndef JOB_ #define JOB_
Header file is graph.h #ifndef _GRAPH_H_ #define _GRAPH_H_ #include <map> #include <vector> using namespace
Header file #include <iostream> #include <cstring> const unsigned MaxLength = 11; class Phone {
I have a C header file like this: #ifndef RENDERER_H #define RENDERER_H static int
I have the following header file: #ifndef DATABASE_H #define DATABASE_H #include <vector> #include <iostream>

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.