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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:33:04+00:00 2026-05-24T09:33:04+00:00

I am thinking of using the builder pattern in C++ unit tests, to streamline

  • 0

I am thinking of using the builder pattern in C++ unit tests, to streamline the creation of input data for the code being tested.

In Java the common idiom seems to be to have the setters of the builder class return the (reference to) the builder object itself, so that multiple setters can be chained in a single line. E. g. the builder class could be defined like this:

// class builder 
public class Builder
{
  private Part1 part1;
  private Part2 part2;
  public Builder withPart1(Part1 p1);
  public Builder withPart2(Part2 p2);
};

And then used like this:

Builder b;
Part1 p1;
Part2 p2;
b.withPart1(p1).withPart2(p2);

The same effect can be achieved in C++ by having the setters return a reference to the builder object. However, I have not been able to find any examples of that on the web. Is this kind of “chaining” a common practice in C++? And if no, then why not?

  • 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-24T09:33:05+00:00Added an answer on May 24, 2026 at 9:33 am

    Yes it’s a common practice, it’s called a “Fluent API”.

    The canonical example:

    while ((std::cin >> std::setbase(16) >> i >> s).getline(s2)) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Builder::XmlMarkup to produce data structures in XML format for a RESTful
I'm using Windows CE Platform Builder and my code is written in C++ .
I was thinking of using mvc pattern while designing this app. How can I
I'm using Thinking Sphinx for full-text search, following this video . I'd like to
I am thinking of using a PHP framework called CodeIgniter . One of the
My company are thinking about using Mono for an upcoming product, so we were
I am thinking about using Microsoft Unity for my Dependency Injection tool in our
We're thinking about using the rufus-scheduler gem on a Ruby on Rails project to
I'm thinking about using log4net in a MOSS(SharePoint) 2007 project, but I need to
I was thinking of using these styles for easier cell rollover effects in a

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.