Discussion Locked

Help with pointers

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do i add the contents of two pointers in C++?

5 replies

by rvk

If you are using pointers to objects and if the objects are user-defined ( which is one of purposes of OOPL such as C++ ):
need to do the following:
1. Define Overload the '+' operator appropriately.
2. Define the assignment operator for that object.
3. Might have to define a copy constuctor depending on whether dynamic memory is used or not

then you can have statement like

target_obj = (*ptr_2_obj1) + (*ptr_2_obj2);
where
target_obj and the objects pointed to by ptr_2_obj1,ptr_2_obj2 are of the same type.

Hope this helps.
Thanks & Rgds

This discussion is closed to new replies.