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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:45:15+00:00 2026-05-13T19:45:15+00:00

In keeping with the practice of using non-member functions where possible to improve encapsulation

  • 0

In keeping with the practice of using non-member functions where possible to improve encapsulation, I’ve written a number of classes that have declarations which look something like:

void auxiliaryFunction(
        const Class& c,
        std::vector< double >& out);

Its purpose is to do something with c‘s public member functions and fill a vector with the output.
You might note that its argument order resembles that of a python member function, def auxiliaryFunction(self, out).

However, there are other reasonable ways of choosing the argument order: one would be to say that this function resembles an assignment operation, out = auxiliaryFunction(c). This idiom is used in, for example,

char* strcpy ( char* destination, const char* source );

What if I have a different function that does not resemble a non-essential member function, i.e. one that initializes a new object I’ve created:

void initializeMyObject(
    const double a,
    const std::vector<double>& b,
    MyObject& out);

So, for consistency’s sake, should I use the same ordering (mutable variable last) as I did in auxiliaryFunction?

In general, is it better to choose (non-const , const) over (const, non-const), or only in certain situations? Are there any reasons for picking one, or should I just choose one and stick with it?

(Incidentally, I’m aware of Google style guide‘s suggestion of using pointers instead of non-const references, but that is tangential to my question.)

  • 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-13T19:45:15+00:00Added an answer on May 13, 2026 at 7:45 pm

    The STL algorithms places output (non-const) values last. There you have a precedent for C++ that everyone should be aware of.

    I also tend to order arguments from important, to less important. (i.e. size of box goes before box-margin tweak value.)

    (Note though: Whatever you do, be consistent! That’s infinitely more important than choosing this or that way…)

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

Sidebar

Related Questions

I have written an HttpModule that spawns a background thread. I'm using the thread
Generally, it is good practice to avoid GOTOs. Keeping that in mind I've been
What is best practice for keeping API keys and access details for the database
Is keeping JMS connections / sessions / consumer always open a bad practice? Code
I've got 3 dataset objects that are nested with each other using entity set
I've been using C on some projects for a master's degree but have never
Question: What is best practice for form submissions while keeping in mind security? This
I'm using Ogre3D, so I'm using several classes who inherits Ogre and OIS classes
I have a java application which I have implemented its' database connection using singleton
I've read that it's bad practice to style content based on HTML5 data-* attributes.

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.