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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:19:50+00:00 2026-06-13T16:19:50+00:00

I am trying to learn some OOP and I have a problem understanding the

  • 0

I am trying to learn some OOP and I have a problem understanding the following program:

#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;

class A
{
public:
    A(int i) : m(i){}

    friend class B;

    friend void g_afiseaza_m();
private:
    int m;
};

class B
{
public:
    void afiseaza_m()
    {
        A a(250);
        cout<<"clasa B este prietena cu clasa A"<<endl<<" poate accesa membrul privat A::m"<<endl<<a.m<<endl;
    }
};

void g_afiseaza_m()
{
    A a(300);
    cout<<"functia g_afiseaza_m nu este un membru al clasei A dar este prieten"<<endl<<"poate accesa membrul privat A::m"<<endl<<a.m<<endl;
}

int main()
{
    B b;
    b.afiseaza_m();
    g_afiseaza_m();
    getch();
    return 0;
}

Can you please tell me what does this line do: public:A(int i) :m(i){} private: int m?
I undestand that A is a constructor with the int parameter i, and that m is a private member of class A but I can’t understand what is m(i) ? Is this a matter of syntax ?

  • 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-13T16:19:51+00:00Added an answer on June 13, 2026 at 4:19 pm

    The m(i) in your constructor initializes the m member with value i.

    Your example has the same outcome (and not behaviour) as

    A(int i) {
        m = i;
    }
    

    Initializing members using initializer lists as in your example is more efficient because the member’s constructor is called directly with parameter i whereas in the example above, the empty constructor of m is called and then m is assigned value i.

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

Sidebar

Related Questions

I've trying to learn PHP OOP and have made some research on how to
I am trying to learn OOP in PHP, and I have some confusion about
I am trying to learn some DirectX API and, for now, I have just
I'm trying to do a little PDO CRUD to learn some PDO. I have
I'm trying to learn some programming with jQuery. I have a div that has
trying to learn some html/css and I'm having a problem with fixed position divs.
I'm trying to learn some basics of Ruby on Rails and encountered a problem
I'm trying to learn some graphics programming using C. What would be the best
I am trying to learn some PHP using the book titled PHP for Absolute
I am newbie trying to learn some code. I am following the tutorial on

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.