<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C++ classes and operators</title><link>/technologies/code_exchange/b/blog/posts/c-classes-and-operators</link><description>This is a &amp;quot;classic C++&amp;quot; post, something that&amp;#39;s been part of the language since conception: How to use an operator in your class design.
I developed a callback class. Your &amp;quot;gizmo that needs to callback something&amp;quot; would hold an instance of that class (</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: C++ classes and operators</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/c-classes-and-operators</link><pubDate>Sun, 09 Mar 2025 19:47:22 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:e9566ac9-093b-41ed-a91a-a02864619729</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Here is how I used this in Raspberry Pico code, where I use a callback when i need data from UART:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:544192ac-a28d-4462-b7a6-33a10a260723:type=csharp&amp;text=callbackmanager%3A%3ACallback%3Cvoid%2C%20std%3A%3Astring%26%3E%20reader%3B%0A%0Areader.set%28%5B%5D%28std%3A%3Astring%26%20s%29%20-%3E%20void%20%7B%20read%28s%29%3B%20%7D%29%3B%0A%2F%2F%20read%20is%20a%20Pico%20function%20that%20gets%20all%20available%20data%20from%20the%20controller%27s%20UART%20buffer.%0A%2F%2F%20it%20stores%20the%20results%20in%20the%20std%3A%3Astring%20tht%27s%20passed%20to%20it%20as%20a%20reference.]&lt;/p&gt;
&lt;p&gt;In my business logic, that doesn&amp;#39;t know anything about Pico or UART, I invoke a read by calling that callback:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:f78c1ef4-9de2-4db7-ab40-d1a5474465af:type=csharp&amp;text=%2F%2F%20In%20my%20business%20logic%0A%0Avoid%20mybusinessclass%3A%3Aread%28std%3A%3Astring%26%20s%29%20%7B%0A%20%20%20%20reader%28s%29%3B%0A%7D]&lt;/p&gt;
&lt;p&gt;The callback class will call that read() function we set earlier, to get the data from the UART, and put it in std::string s.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28759&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>