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

What are security issues in the C language?
Even though the C language is widely used in different systems still it has many security flaws associated with it. This article focuses on discussing security vulnerabilities in the C language. Mainly...
Avinesh
0 0
7
What is a pragma?
In computer programming, a directive pragma is a language construct that specifies how a compiler should process its input. The ' #pragma ' directive is the method specified by the C standard for providing...
Anil
What is the best python institute
All institutes are best, but you should check with the instructor, how will teach and guide you
Dinesh

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

Ask a Question

Related Lessons

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...

What is the difference between PHP and PYTHON
Let's start with PHP: - Ideal for standard web development- Easy integration with MySQL- $_GET and $_POST built into the language- C-Esque syntax Primarily used on an Apache server (Routinely, you...

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

Build an interactive Dictionary using Python 3.x
I have downloaded a 5MB data base consisting of words and their meanings in a json file . I want to write a python progrsm which will ask the user to enter a word and then the program will search through...
B

Biswanath Banerjee

0 0
0

How Machine Learning Predict things - A Short Video for absolute beginners
Here is a short video for Machine Learning Beginners, who want to know how Machine Learning Algorithm predict things

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