General discussion

Locked

Help with pointers

By sword_fish101 ·
How do i add the contents of two pointers in C++?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Help with pointers

by R. A. Caluste In reply to Help with pointers

value = (*ptr1) + (*ptr2)

Collapse -

Help with pointers

by sword_fish101 In reply to Help with pointers

The question was auto-closed by TechRepublic

Collapse -

Help with pointers

by rvk In reply to Help with pointers

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

Collapse -

Help with pointers

by sword_fish101 In reply to Help with pointers

The question was auto-closed by TechRepublic

Collapse -

Help with pointers

by sword_fish101 In reply to Help with pointers

This question was auto closed due to inactivity

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums