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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:45:07+00:00 2026-06-18T01:45:07+00:00

class a { public: a() : b(5), a1(10) //will firstly initialize a1 then b,

  • 0
 class a
 {
 public:
 a() : b(5), a1(10) //will firstly initialize a1 then b, so order here doesn't matter
 int a1;
 private:
 int b;
 }

The question is how to change the order (to have b initialized before a1)? I must have public members above private so that solution isn’t okay for me. Of course here I use ints, the problem is more complex but it’s just an example which shows what is my problem.

  • 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-18T01:45:08+00:00Added an answer on June 18, 2026 at 1:45 am

    If I understand you correct you have some kind of style guide saying that public members should be before private.

    In that case I would suggest you declare all your member variables private and create accessor functions to them instead. That way you get around it.

    class a
     {
     public:
       a() : _a1(5), _b(10) 
       int a1() const { return _a1; }
       void a1(int value) { _a1 = value; }
       int b() const { return _b; }
       void b(int value) { _b = value; }
    
     private:
       int _a1;
       int _b;
     }
    

    any sane compiler will anyway optimize it so the overhead will be minimal.

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

Sidebar

Related Questions

if my class is private and constructor is public then what will happen. can
class MyClass { public: void method2() { static int i; ... } }; Will
I'm creating a class that will have one public method, which returns a value
I have this class: public class MyEntity { public virtual int Id { get;
I have a public class I'm defining that will eventually be part of an
I have a class: public class class1 { public string Property1 {get;set;} public int
Here, the listbox is loaded sample Text. My Model.aspx will be public class Employee
I have a two classes: public class Question { public IList<Answer> Answers { get;
I have developed a code that will start two threads upon executing public class
I have an already existing generic class public class Foo<T> { private T _item;

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.