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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:41:31+00:00 2026-06-04T00:41:31+00:00

I have been reading through this similar question and find myself less than satisfied

  • 0

I have been reading through this similar question and find myself less than satisfied with the responses. I don’t have a simple function called “foo”; I have a much more complex function which has very real dangers if parameters are not supplied judiciously. It seems preferable to me for the function to enforce its own rules and ensure system robustness than to lean towards semantic niceties which insist on “one function, one thing to do”. I think the favoured responses given to that question reflect programming idealism taken too far, not the reality of certain situations.

What I face is:

void DoSomethingVeryComplex( const CRect bounds, CPoint startPoint = CPoint(-1,-1) );

Now this happens to satisfy the semantic rules – it is doing some thing, not several things. The one thing it is doing happens to be complex, and multi-staged, but it is still one thing.

For that complex thing, it is recommended that the user supply the bounds, and let the function determine its own starting point. Advanced users might want to do the considerable math to determine a specific alternative starting point and supply that… but users beware.

And now I have come to see that on rare occasions, it makes sense to supply not one, but several starting points. This changes nothing in the semantic concept of the process involved, because the process is one which spreads from one point to neighbours, to neighbours of neighbours, and so on. So starting from many points is a natural extension.

Accordingly, I would prefer to specify:

void DoSomethingVeryComplex( const CRect bounds,
                             const std::vector<CPoint> startPoint /* = empty" */ );

so that if the vector is empty, the function determines the start point as before, and if there are any points in the vector, they are used as start point(s).

Is there a C++ syntax available which allows me to do this – to specify an empty array as a default parameter?

  • 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-04T00:41:33+00:00Added an answer on June 4, 2026 at 12:41 am

    In C++11, it’s simplest:

    const std::vector<CPoint> startPoint = {}
    

    Before that, this will work:

    const std::vector<CPoint> startPoint = std::vector<CPoint>()
    

    Both of these invoke the default constructor, which creates an empty vector. Note that the same syntax can be used to call other constructors as well, as long as you fill in the appropriate arguments.

    //this one has 5 default-constructed CPoints
    const std::vector<CPoint> startPoint = std::vector<CPoint>(5) 
    

    In C++11, you can even fill out a default vector:

    const std::vector<CPoint> startPoint = {CPoint(1, 2), CPoint(4, 5), CPoint(3, 9)}
    

    If you want that kind of capability for your own classes, here’s a link on how it works.

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

Sidebar

Related Questions

I have been reading through this wonderful website regarding the recommended Python IDEs and
I've been going through here reading about similar question, and I haven't been able
I have been reading through a lot of answers of questions that are similar
I have been reading through this tutorial . I am in a chapter where
I have been reading through the documentation on the JavaScriptMVC framework and it looks
I've been reading through this tutorial for using a SQLite database within an iPhone
I have been searching through the web and reading many posts, but none has
I have been reading through the core data documentation and feel I am still
I have been reading through C++ Template Metaprogramming and doing the exercises contained therein
I have been reading through questions * and answers about how to stop an

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.