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

PHP (LAMP) for entrepreneurs, is there any full time, fast track classes on PHP(LAMP) for entrepreneurs, who want are want to do some tech part in their startups
Yes, You have option. You can Join. Xpert Infotech, New Delhi. Before going through Silverlight live project training candidate should have knowledge of given concepts listed below: Knowledge of HTML...
Saee
0 0
6
What is a C++ identifier?
The C++ identifier is a name used to identify a variable, function, class, module, or any other user-defined item. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero...
T.v.
0 0
6
How can I learn PHP?
first understand what is web server. then what is server side programming language. then start understanding how submitting form can reach to a php program. how get and post work. then
Diwaker
hello sir my name is suryateja i am studying in diploma in computer science and engineering my college complect in c language subject i practice with in simple programs my write to won programs how it you?
Hi Syateja, if I understand your questions correctly let me answer. Best thing to learn and progress is to practice writing programs, initially small programs then gradually can write complex program....
Suryateja

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

Ask a Question

Related Lessons

C++ Program Sample Application
//Standard Library Functions(Headers Files Used in C++) #include<iostream.h> #include<conio.h> //Main function int main() { //function for clearing the screen clrscr(); //function for...
S

Hiding .php extension Using HTACESS File
If you wish to hide.php extension from your website, then create a .htaccess file in your project root and paste the following code : RewriteEngine On RewriteCond %{THE_REQUEST} ^{3,}\s/(.+)\.php*...

STORAGE CLASSES
A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program. They precede the type that they modify. We have four different storage classes in a C program: auto register static extern ...

Why we need to learn Programming languages?
Language is medium for communication. If two parties like to communicate or exchange the thoughts they must know a language. Language should be understandable by both the Parties. For example A wants to...

Back Reference In Python Regex
What if your interviewer asks about this? We know Regex have some useful functions like: match ( Ex: re.match(pattern,dataSource) ) search ( Ex: re.search(pattern,dataSource) ) sub ...

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