What syntax do you use to have two objects of the same class interact
with each other in their respective functions?
and from Google, 'syntax' is defined as
... the arrangement of words and phrases to create well-formed sentences
in a language.
In this context, I'm not sure what you mean by syntax.
As a starting point, and something to write about,
- in telecomm embedded systems, I dealt with working/protect pairs, all in C++.
hardware context:
- Almost all work/protect hw is exchangeable ... it was ok to simply swap the cards slots.
Software context:
- The work and protect cards were "...two objects of the same class."
Work and protect cards cooperated by hw for 'fast' response, and software discovered any actions (take by the hw) within the next second.
Work / protect has implications to the ctor:
a) Both cards are constructed without assumptions about the other's presence.
Note: if the other is never installed, the system would still work, just without the 'recovery' behavior.
Roughly similar to how two soldiers would never fight when only 1 of them existed.
b) When the controller code is ready to create the second (of a pair), it knows that the first work/protect card is ready. It simply constructs the second, and then passes a reference into the latest construct, about the first sibling.
c) Upon receipt of the sibling reference, the second object of the two would update both instances. I usually gave the reference to the second card immediately after the second card ctor had completed (without errors).
Note: In C++, sibling instances of the same object class have full access to the other, when provided a reference or pointer.
I also contributed to battle simulation effort (prior to telecomm).
Further interactions (of a battle) can be taken individually by each soldier, if your controller provides each soldier with the stimulus, i.e. invoke a function.
You also may find that, upon receiving a stimulus, it may be easier when one soldier instance takes a single stimulus related action on both soldier instances.
In a battle sim effort I worked on some time ago, all sim actions were stimulated by weapon fire (and, in that case, a laser signal). Distance and weapon type (tank vs ar15) influenced the lethality when hit (as detected by laser sensor).
That software was greatly simplified because every participant (and node in the sim) was both a weapon AND a target.
Good luck in your effort.
Probably final comment:
I generally do not pass objects to functions. Instead I invoke functions of objects. There are many articles about this issue. I can recommend:
see: https://pragprog.com/articles/tell-dont-ask
see also: https://martinfowler.com/bliki/TellDontAsk.html
Tell-Don't-Ask is a principle that helps people remember that object-orientation is about bundling data with the functions that operate on that ...
Martin Fowler