Pointers to members, C/C++ Programming

Assignment Help:

Pointers to Members:

In C a pointer is created  to locate  the address of another variable  for faster access.

Consider the following example. int x, *p;

p = &x;  Pointer p is pointing to the address of x, remember a pointer is also a variable and it has its own address.  The above technique is fine as long as the variable is of primary data type not in the class.  If the primary data type is inside the member of a class which is known as data member then the indirection operator * is not valid, instead operator ::* must be used.

Rules for declared pointer to the class and its member:

1.  Only Class and its member can be declared as pointer (M *pm).

2.   Members are declared as pointer through its class (int M::* px).

3.   When class is declared as pointer members must also be declared as pointer to access the member.

4.   When only members are declared as pointer the member can be accessed using given synatax  (object_name.*pointer-to-member)

5.   When class is declared as pointer remember member must also be a pointer such member can be accessed with given syntax (object_name->*pointer-to-member)

6.   Only Member function are declared as pointer void(M::*pf)(int,int), for member function the pointer must be within( ) and it must specify type of argument just like function.

7.   Using only member function as pointer  (op.*pf)(30,40);

8.   Class and member function declared as pointer accessing is (op->*pf)(30,40);


Related Discussions:- Pointers to members

Flight Departure in C, I really have a hard time analyzing how to write a c...

I really have a hard time analyzing how to write a code in C. It''s all bout Time Departure and we must used a 24 hour clock. Can u help me?

Define the data types of c language, Define the Data Types of c language? ...

Define the Data Types of c language? The C has a concept of 'data types' which are used to define a variable before its use and the definition of a variable will assign storage

What is an iterator class?, A: A class which is used to traverse through th...

A: A class which is used to traverse through the objects maintained through a container class. There are _ve categories of iterators: output iterators, input iterators, forward ite

Implementation of the stack class in c++, Implementation of the Stack class...

Implementation of the Stack class in C++: How to implement stack class in c++. int Stack::push(int elem) {    if (top    {       list[top++] = elem;       r

Binary search tree and graph, Important Note: No course works, which have b...

Important Note: No course works, which have been submitted via hard copies or emails, will be accepted a short essay below edited in a document (word, other) files with

Intro to C++ Lab Help, I have a very confusing assignment and I''m struggli...

I have a very confusing assignment and I''m struggling to find the right place to begin or how to break the problem down.

What are some ways try / catch / throw can develop software , Q: What are s...

Q: What are some ways try / catch / throw can develop software quality? A: By removing one of the reasons for if statements. The commonly utilized alternative to try / catch

Should one design a classes from the outside, Should one design a classes f...

Should one design a classes from the outside (interfaces first) or inside (data first)? A: From the outside. A superior interface provides a simplified view which is express

Arrays within a class, A r r a y s w i t h i n a c l a s s:...

A r r a y s w i t h i n a c l a s s: I t i s j u s t d ecl a r i n g o r c on s t ru c ti n g a d e r i v e d t

C code, how can i easily make a program?

how can i easily make a program?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd