Discussion Locked
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
value = (*ptr1) + (*ptr2)
The question was auto-closed by TechRepublic
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
The question was auto-closed by TechRepublic
This question was auto closed due to inactivity
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending
Discussion Locked
What Makes a Business Website Effective in 2026
2 helpful
10 replies
1 helpful
3 replies
Question
Windows and macOS computers becoming slow or unstable after updates - what should I check first
0 helpful
1 reply
Question Unanswered
Best Way to Make Long WordPress Location Guides Mobile Friendly
0 helpful
0 replies
Discussion
Optimizing WordPress widgets and DOM size
0 helpful
3 replies