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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:51:47+00:00 2026-06-08T18:51:47+00:00

In the following C++ code: struct Features { int F1; int F2; int F3;

  • 0

In the following C++ code:

struct Features {
  int F1;
  int F2;
  int F3;
  int F4;
  Features(int F1,int F2,int F3,int F4)
  : F1(F1), F2(F2), F3(F3), F4(F4) { }
};

What does this part mean?

Features(int F1,int F2,int F3,int F4)
      : F1(F1), F2(F2), F3(F3), F4(F4) { }

Thanks.

  • 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-08T18:51:48+00:00Added an answer on June 8, 2026 at 6:51 pm

    It is initializing the member variables using the constructor’s initializer list. it would be clearer if the names of the constructor parameters weren’t the same as the data members:

    Features(int a,int b,int c,int d)
          : F1(a), F2(b), F3(c), F4(d) { }
    

    It is useful to have some naming convention for data members, such that these are easily identifiable and distinguishable from local variables in code. Examples are prefixing an m_ or using a trailing _:

    struct Features {
      int m_f1;
      int m_f2;
      int m_3f;
      int m_f4;
      Features(int f1,int f2,int f3,int f4)
      : m_f1(f1), m_f2(f2), m_f3(f3), m_f4(f4) { }
    };
    

    Both these constructors can be used like this:

    Features f(11,22,33,44);
    std::cout << f.m_f1 << "\n"; // prints 11
    std::cout << f.m_f2 << "\n"; // prints 22
    std::cout << f.m_f3 << "\n"; // prints 33
    std::cout << f.m_f4 << "\n"; // prints 44
    

    Note that the fact that this constructor has been defined means that the compiler will no longer provide a default constructor. So if you want to be able to to this:

    Features f;
    

    then you need to provide your own default constructor:

    Features() : m_f1(), m_f2(), m_f3(), m_f4() {} // initializes data members to 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code: struct Foo { Foo(int x=0); }; Does the constructor count
Say I have the following code: struct date { int day; int month; int
I have the following code: class outer { struct inner { int var1; int
Consider the following code: struct Foo { mutable int m; template<int Foo::* member> void
I have the following code struct Node { int accnumber; float balance; Node *next;
Given the following code: public struct Foo { public Foo(int bar, int baz) :
consider the following code:- struct mystruct { int data; struct mystruct *next; }; void
Consider the following code struct foo { const int txt_len; const int num_len; char
I have the following code: struct simple { simple (int a1, int a2) :
I have the following code: struct VRfile{ char sessionID[10]; char file[20]; int first; };

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.