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

Are C Programmers currently in demand?
Ofcourse, C is alwasy in demand. In the beginning a lot of the big project developed in C language. Now a days, there are a lot of language in market and speciallity is growing in IT field. For a big organization...
Harsha

is there an best online exam simulator for PCAP 31-02 python exam ?

yes, this will work Python exam in cisco net grade, it 's free and help in practice and if you clear this exam, you will get 50% off PCAP 31-02 exam coupon on your registered email id.
Rajgun
0 0
5
What is a macro, and how do you use it?
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look...
Sandeep
How do you list a file's date and time?
The C date and time operations are defined in the time.h header file time_t current_time; char* c_time_string; /* Obtain current time. */ current_time = time(NULL);
Neelima
0 0
6
What is important topics in C-language for interviews???
Functions, Arrays , String, pointers , structures
Gayu

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

Ask a Question

Related Lessons

An Interesting discussion about malloc( ) and calloc( )
What are malloc( ) and calloc( )? Simply putting they are the predefined functions in C language. Malloc( ) and calloc( ) are two such functions which are used for more or less identical purpose and...

How to Create A Master Page Template In PHP?
A master page template is essential to give a consistent look and feel to any website having multiple pages. It is quite easy to create a master page template in PHP using Dreamweaver. Let’s have...

All About Programming And A Good Programmer.
Hi, This is my first lesson for you guys. Hope you enjoy reading it. In recent community questions, I found many people wanted to be good programmers, or wanted to have good hands on certain language,...

FUNDAMENTALS OF COMPUTER ALGORITHMS
INTRODUCTION: The word algorithm is named after the ninth century scholar 'Abu Jafar Muhammad Ibn Musa Al-Khwarizmi'. An algorithm is a step-by-step procedure by which a computer can produce the required...
M

Mukesh Tekwani

2 0
0

Do You Know Size Of Empty Class and Reason?
Size of empty class is always 1 byte. Reason is, in order to differentiate one object to another object, the size of empty class is always 1 byte. See the below c++ code snippet. Here there are three...

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