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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:54:15+00:00 2026-05-14T08:54:15+00:00

Well, here we are. Yet another proposed practice that my C++ book has an

  • 0

Well, here we are. Yet another proposed practice that my C++ book has an opinion on. It says “a returning-value(non-void) function should not take reference types as a parameter.” So basically if you were to implement a function like this:

int read_file(int& into){
   ...
}

and used the integer return value as some sort of error indicator (ignoring the fact that we have exceptions) then that function would be poorly written and it should actually be like

void read_file(int& into, int& error){

}

Now to me, the first one is much clearer and nice to use. If you want to ignore the error value, you do so with ease. But this book suggests the later. Note that this book does not say returning value functions are bad. It rather says that you should either only return a value or you should only use references.

What are your thoughts on this? Is my book full of crap? (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-05-14T08:54:15+00:00Added an answer on May 14, 2026 at 8:54 am

    The advice is silly. A direct return value is much smaller and easier to type.

    Direct return:

    if (read_file(...)) {
        ... handle problem ...
    }
    

    Indirect return:

    int status;
    
    read_file(..., status);
    if (status) {
        ... handle problem ...
    }
    

    Edit: a bigger issue is whether to use non-const reference parameters at all. It can be surprising to have side effects come flying out of the parameters. One coding standard says that reference parameters should be const and output parameters should use pointers. That way the reader gets a & at the point of call that shouts out “something happens to this parameter”.

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

Sidebar

Related Questions

Well, here is my problem: I have an application that uses a custom Javascript
Another slightly non-technical question, but I couldn't decide whether to ask here or on
I've yet another question. I'm working with GWT 2.0.4 and IE8 as well as
Extreme Android developer newbie here...well, new to Android development, not development in general. I
Well i am here writing some constraints for a db I am working on
Here is well described how to call member function by pointer: http://www.newty.de/fpt/functor.html But the
The question of composite keys in web2py was answered pretty well by Anthony here
Well i need some help here i don't know how to solve this problem.
Well, Here is the C++ code I've got here and cant compile #include <iostream>
Here is my code (well, some of it). The question I have is, can

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.