UrbanPro

Learn Programming Languages from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

what we can access private data of any class without using member function

Asked by Last Modified  

Follow 0
Answer

Please enter your answer

There are two ways to access it. 1) Friend functions can access the private data of the class. 2) Typecast the object address to a pointer and then access the individual variables through memory access. Below example explains this in detail. class Test { private: int a; ...
read more
There are two ways to access it. 1) Friend functions can access the private data of the class. 2) Typecast the object address to a pointer and then access the individual variables through memory access. Below example explains this in detail. class Test { private: int a; char b; }; void somefunc () { Test obj; int *x; char *y; // x points to member variable 'a' after below call. x = (int *) &obj; // y points to member variable 'b' after below call. y = (char *)(x + 1); *x = 3; *y = '='; } This method is however not recommended. The ideal method is to use public member functions for all operations on class object. read less
Comments

Yes, it is possible using pointers.
Comments

Trainer

Assessing the Private Member without Member Function or Friend Function is possible in C++. But it is little tricky. This is not known to many of the programmers. But such private member accessing needs some tweeks in the class.
Comments

IT Professional Trainer working with a reputed Institute. Headquarters: Hyderabad

In C++ there is a function called friend function, which allow us to access the private data of the class, A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class.
Comments

Excel VBA Expert

we can not
Comments

IT Professional Trainer with 15 years of experience in IT Industry

Actually not possible to access private variables in other classes without using public member function. But you have to find it then you can be share with us..
Comments

if u want to share your private data to the person who is not ur family member,you can do it by making him/her ur friend.don't do it always.
Comments

Assitant professor with 6 years of teaching experience.

It is not possible to access private members of a class without its own member function. That is the main reason why it is set as private so that members of other class should not be able to directly access private member of the class.
Comments

Software Professional Trainer with 26+ years of Experience in Software Design and Development

Using friend function you can access the private data of a class through object. The other way is you can get the address of the object. From this address, you can traverse the variable based on the size and get the value of the variable. But this will void the OOPs concept. Example Class Student...
read more
Using friend function you can access the private data of a class through object. The other way is you can get the address of the object. From this address, you can traverse the variable based on the size and get the value of the variable. But this will void the OOPs concept. Example Class Student { private: char charstudentname[20]; int studentid; public: void SetStudentData() { strcpy(studentname,"Ram"); studentid = 123; } }; void main() { Student student; int *ptr; // to get access private member studentid directly here, use the following statement ptr = &student; ptr = ptr + 20; // id is available after 20 bytes(20 characters of student name) cout << *ptr; // will display the student id 123 } read less
Comments

Trainer

Private data can be accessed in only members functions. Even if you create a object you cannot access the private data.
Comments

View 10 more Answers

Related Questions

Can I become an expert in Visual Basic Training?
Have confidence. You can learn anything.
Kanu
Is C destined to die?
No not at all
Anubhav
0 0
5
Which is the best book for understanding concepts of c language?
There are several good books for learning C programming. Here are a few highly recommended ones: "C Programming Absolute Beginner's Guide" by Perry and Miller: A great choice for absolute beginners,...
Chetana
0 0
7
What is polymorphism in C++?
https://vz-3ad30922-ba4.b-cdn.net/22b3f0e4-e072-48b7-9ae6-3d65a6b4ad50/play_480p.mp4
Renu
0 0
5
If I get trained in python is there any chance to get a job as a fresher
While no one can guarantee getting a job after being trained as it depends on the trainer and the person being trained but yes, getting a job as a fresher in python is relatively easy compared to other...
Sai
0 0
6

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Five exercises on numbers that will help you develop your logic
If you want to become a programmer (web developer) you need to have good logical thinking skills. Programming is all about planning and building logic. Here is a set of exercises that will help you develop...

How to work fast while working on MS Excel?
Many people struggle to find out the way on how they can work faster while working on MS Excel/Access or VBA. let me share the tip for that. If you are new or working since long time on Excel/Access...

Importance Of Function Prototype In C
Function prototype tells compiler about number of parameters function takes, data-types of parameters and return type of function. By using this information, compiler cross checks function parameters and...

5 Key Benefits of Internship
As many of my connects are about to complete their graduation and post graduation, its been my good advice to them to find internship. Let me throw some light in this article on that area. An internship...
S

Shekhar Pawar

0 0
0

Getting started with Python IDLE
Now that we have looked at some example programs, we would like to learn how to begin the actual process of writing a program in Python. There are a variety of ways to tell Python to execute the code we...

Recommended Articles

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Looking for Programming Languages Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Programming Languages Classes?

The best tutors for Programming Languages Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Programming Languages with the Best Tutors

The best Tutors for Programming Languages Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more