Use a Struct Instead of a Long Argument List

Functions having a long list of arguments such as:

 void retrieve(const string& title, const string& author, int ISBN,  int year, bool&  inStore); 

can become a maintenance problem, since their argument list is likely to be changed in the future. For example, a URL with a book cover image may be added or other arguments may be omitted. Consequently, every occurrence of a function call has to be modified appropriately. A better solution is to pack the entire argument list in a single struct and pass it by reference (or by address in C) to the function:

 struct Item{string title;string author; int ISBN;  int year, bool  inStore };void retrieve(Item& book);

The advantages of this technique are obvious:

1. Maintenance. Every modification will be localized to the definition of the struct, but no other code modifications will be required.
2. Performance. Since a reference is all that has to be passed to the called function, you may gain a slight performance boost.
3. Future extensibility. A struct can serve as a base for other classes. It may be extended to have member functions as well.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a