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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:09:30+00:00 2026-06-03T09:09:30+00:00

I am playing with the fluent interface pattern. First, I wrote something like that:

  • 0

I am playing with the fluent interface pattern.

First, I wrote something like that:

class C
{
public:
    C() { }

    C* inParam1(int arg1){ param1 = arg1; return this; }
    C* inParam2(int arg2){ param2 = arg2; return this; }

private:
    int param1;
    int param2;
}

Then I tried to use the std::unique_ptr, but then I realized that I do not know how to “shift” the pointer (this) along the chain. I tried something like:

return std::move(this);

that of course does not work.

How can I do this? Are there any problems doing something like this?

In order to reply to comments like: “do not use pointers”: there isn’t (yet) any practical reason because I am doing this with pointers, is just something I wonder if can be done this way.

  • 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-03T09:09:31+00:00Added an answer on June 3, 2026 at 9:09 am

    Why do you have to return pointers at all?

    class C
    {
    public:
        C create() { return C(); }
    
        C & inParam1(int arg1){ param1 = arg1; return *this; }
        C & inParam2(int arg2){ param2 = arg2; return *this; }
    
    private:
        C() { }
        int param1;
        int param2;
    };
    

    I must admit I don’t understand the purpose of that create function or why the constructor is private or how you actually create objects of this class at all. In my understanding, the class should actually be like this:

    class C
    {
    public:
        C() {}
    
        C & inParam1(int arg1){ param1 = arg1; return *this; }
        C & inParam2(int arg2){ param2 = arg2; return *this; }
    
    private:        
        int param1;
        int param2;
    };
    

    And used like this:

    int main()
    {
        C().inParam1(10).inParam2(20).whatever();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While playing around with regexps in Scala I wrote something like this: scala> val
Playing around with MSVC++ 2005, I noticed that if the same class is defined
Playing with jquery for the first time, and I'm trying to get a simple
Playing around with MongoDB and NoRM in .NET. Thing that confused me - there
Playing with Erlang, I've got a process-looping function like: process_loop(...A long list of parameters
Im playing a little bit with heavy-client app. Imagine I have this model: class
Im playing with my smart pointer class and I want to implement ++ and
While playing around with the emulator, I noticed that when trying to view a
playing around with a property file i figured that there seems to be a
Playing with a Mobile application in ASP.NET MVC4 beta, using great that article ,

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.