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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:55:27+00:00 2026-06-04T21:55:27+00:00

I am learning basic concepts of OOP in C++ and I came across a

  • 0

I am learning basic concepts of OOP in C++ and I came across a logical problem.

#include <iostream>
#include <conio.h>

using namespace std;

class A {
    int i;
public:
    void set(int x) {
        i=x;
    }
    int get() {
        return i;
    }
    void cpy(A x) {
        i=x.i; 
    }
};

int main()
{
    A x, y;
    x.set(10);
    y.set(20);

    cout << x.get() << "\t" << y.get() << endl;
    x.cpy(y);
    cout << x.get() << "\t" << y.get() << endl;
    getch();
}

I wanted to know in the above code why am I able to access x.i [Line 19] ,it being a private member in the different object.Isn’t the private scope restricted to the same class even if the object is passed as a parameter?

  • 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-04T21:55:27+00:00Added an answer on June 4, 2026 at 9:55 pm

    private in C++ means private to the class, not private to the object. Both interpretations are possible, indeed some languages chose the other. But most languages are like C++ in this and allow objects of the same class to acces another instance’s private members.

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

Sidebar

Related Questions

I'm using firefox as my default browser for my basic webdev learning process and
What is the next logical step for language learning after learning BASIC?
I'm learning basic c# using visual studio 2010 and I'm creating an application which
I am currently learning about basic networking in java. I have been playing around
I am developing a basic LCMS (Learning Content Management System) and I have to
As a learning exercise I'm building a basic scientific computation environment based on .NET.
I have started learning HTTPUNIT and found one basic example. In this example it
I'm learning Java EE 6 and I'm beginning with basic tutorials trying to really
I'm learning assembly and I have a very basic loop here segment .data msg:
I was learning socket programming and tried to design a basic http client of

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.