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

Why does â??5/2 = 2â?? and not 2.5 in Python?
Due to dynamic Typing. use Numpy , and declare data type , you will get desired result
Srikanth
0 0
6
Which is better, PHP or Python? Why?
Python . Simple syntax,More readable,General purpose programming language
Kartheek
0 0
5
What are the toughest topics in C language?
1. pointer 2. dynamic memory allocation 3. File handling
Lokayya
0 0
5
Why is there no C-- language that simplifies the C language?
Creating C-- to simplify C isn't necessary; evolving languages like Rust, Go, or C++ offer modern alternatives.
Komal
0 0
7
Looking for Yii Framework experts who are willing to train.
A constructor is a special method of a class in object-oriented programming that initializes an object of that type. A constructor will have same name as the class, and can be used to set the values...
Pritam

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

Ask a Question

Related Lessons

Write your first Python program in 10 minutes
1. Download python from python official site search "python download" in google 2. Install in your machine 3. verify using : "python --version" command 4. Write first program using notepad create...

Personalise touch of training & learning
We all are in countinous learning phase in life. Day to day we are learning new things,new language words,new faces,new gazets by all means of modes like reading books,newspapers,watching TV,movies,meeting...
S

Smartnub Softsolutions

0 0
0

Array vs Linked List
Array Linked List Accessing element is easy. Accessing element is difficult compare to Array. Easy to use. Difficult to use. Memory is Fixed size. Memory is variable size. If...

Benefits of Design Patterns in Application Development
Application developments is a tedious job. Programmers write code and test it again and again to make sure their software works fine. So designing complex software is a hard nut to crack. Skilled programmers...

50 Most Common Ruby on Rails Developer Mistakes: Controllers
They use instance variables in controllers Quite often beginners declare all the variables in controllers as instances even if it may not be required. The problem with instance variables is that if you...

Pawan Yadav

0 0
0

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