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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:22:37+00:00 2026-05-23T04:22:37+00:00

I’ve just been having a look at the boost asio framework and the examples.

  • 0

I’ve just been having a look at the boost asio framework and the examples. In the source code for Daytime.3 – An asynchronous TCP daytime server, the code defines a constructor for the tcp_server class as follows:

tcp_server(boost::asio::io_service& io_service) : acceptor_(io_service, tcp::endpoint(tcp::v4(), 50500))

I’m confused as to how the constructor is initializing the acceptor_ instance variable which is defined later on in the private section? I wanted to write equivalent code for this initialization within the body of the constructor (just for learning), but I can’t figure out how this ivar is being initialized.

Many thanks in advance for any help.

  • 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-23T04:22:38+00:00Added an answer on May 23, 2026 at 4:22 am

    Uhm.. why shouldn’t it be able to do so? The member variables are visible through-out the whole class, no matter where they are defined:

    class Foo{
    public:
      Foo(int i) : _i(i) {}
    
    private:
      int _i;
    };
    

    If you meant how that while initialization thing works after the colon :, search for “initializer list”/”ctor initializer” if you want the standard wording.


    Edit: Consider this class:

    class Foo{
    public:
      Foo(int i, float f) : _i(i), _f(f) {}
    
    private:
      int _i;
      float _f;
    };
    

    And now consider this function and other class:

    int random(){
      return 4;
    }
    
    class Bar{
    public:
      Bar() : _f(random(), 3.14159f) {}
    
    private:
      const Foo _f;
    };
    

    You can initialize a member in the initializer list however you want, assuming the member has a fitting constructor. Now, for const member, you can only initialize them that way, because inside the ctor body, it can’t be assigned any more. You could only do that with non-const and non-reference variables:

    class Bar{
    public:
      Bar(){
        _f = Foo(random(), 3.14159f); // invoke copy assignment operator
      }
    
    private:
      Foo _f; // non-const
    };
    

    If this isn’t any help, I guess you really don’t express what you don’t understand.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text

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.