<div dir="ltr"><br><div>Cool thank guys - </div><div>Sounds like a valid design pattern but with garbled syntax...</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 7, 2021 at 9:14 AM jesse brockmann <<a href="mailto:jjbrockm@gmail.com">jjbrockm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>In the class definition use <br><span style="font-family:sans-serif">otherClass *storedReferenceToOtherClass;</span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><span style="font-family:sans-serif"><br></span></div><div dir="auto"><font face="sans-serif">And for the calls use</font></div><div dir="auto"><font face="sans-serif"><br></font></div><div dir="auto"><span style="font-family:sans-serif">storedReferenceToOtherClass->function ()</span><font face="sans-serif"><br></font></div><div dir="auto"><font face="sans-serif"><br></font></div><div dir="auto"><font face="sans-serif"><br></font></div><div dir="auto"><font face="sans-serif"><br></font><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Sun, Mar 7, 2021, 8:32 AM Carl Ott via DPRGlist <<a href="mailto:dprglist@lists.dprg.org" target="_blank">dprglist@lists.dprg.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div>Can somebody help with C++ design patterns?<br><br>I have a class with many methods (first class), that needs access to members of another class (other class).<br>Surely I can pass a reference to the other class into every method of the first class.<br>But that seems like a verbose pain.<br>Instead, I'd like to initialize the first class with a reference or pointer to the other class. Then the first class could use the cached reference or pointer to the other class whenever it's needed.<br>However, I'm missing something - not getting it to work.</div><div><br>Am I just missing syntax or am I fundamentally trying to implement an anti-pattern?<br><br>What are some best practices design patterns to accomplish this?  Any recommendations - where to find a quick tutorial?<br><br><br>here's an abstract of what isn't working...<br><br>class needsToStoreAreference   <br>{<br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>public:</div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>       cacheAreference(otherClass &desiredReference);</div></blockquote></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>private:</div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>   otherClass &storedReferenceToOtherClass;</div></blockquote></blockquote><div>}<br><br>needsToStoreAreference::cacheAreference(otherClass &desiredReference)<br>{<br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div> 

storedReferenceToOtherClass

= desiredReference;     </div><div> // doesn't work, causes an Arduino program to hang</div></blockquote><div>}<br><br><br><br>And in the calling code<br><br>needsToStoreAreference instanceOfNeedsToStore();   // instance of 'first class' in wording above<br><br>otherClass instanceOfOtherClass();             // instance of 'other class' in wording above<br><br>instanceOfNeedsToStore.cacheAreference(instanceOfOtherClass);<br><br></div></div>
_______________________________________________<br>
DPRGlist mailing list<br>
<a href="mailto:DPRGlist@lists.dprg.org" rel="noreferrer" target="_blank">DPRGlist@lists.dprg.org</a><br>
<a href="http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org" rel="noreferrer noreferrer" target="_blank">http://lists.dprg.org/listinfo.cgi/dprglist-dprg.org</a><br>
</blockquote></div></div></div>
</blockquote></div>