Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing a derived-class pointer for a callback
    primarykey
    data
    text
    <p>I'm trying to build a callback-based serial RX driver, and am getting a compile error despite the fact that I'm using a structure which is known good and tested in other applications. I'm sure I'm doing something silly, but for the life of me I can't see it, so a few extra pairs of eyes would be much appreciated.</p> <p>The device should function as follows:</p> <ol> <li>On construction, pass in the comms properties</li> <li>For synchronous communications, do not create a new thread, just block on the TX.</li> <li>For receiving data, spawn a new thread, and execute a callback passed in by the user on RX.</li> </ol> <p>To implement this, I have a base callback class as follows:</p> <pre><code>namespace ocular { Class DeviceCallback { public: DeviceCallback(){} ~DeviceCallback(){} virtual void DeviceCallbackFunction(unsigned char Data){} }; } </code></pre> <p>And the Start Asynch RX method within the device class itself as:</p> <pre><code>void DeviceClass::StartAsynchRX( DeviceCallback* callback ) { m_externalCallback = callback; // Save a local copy of the callback pointer m_started = true; StartAsynchRXThread(); // Spawn the RX Thread return; } </code></pre> <p>I am then deriving my own callback as:</p> <pre><code>Class DemoCallbackClass : public ocular::DeviceCallback { public: void DeviceCallbackFunction(unsigned char myData){ std::cout &lt;&lt; myData; }; } </code></pre> <p>As far as I can tell, this is textbook correct thus-far. This will compile just fine and I can construct, configure and use my device class for synchronous TX. The compile error appears when I attempt to actually start passing the callback pointer in main:</p> <pre><code>void main(void) { DeviceClass MyDevice(); MyDevice.Initialise( *settings from file* ); DemoCallbackClass MyDemoCallback(); MyDevice.StartAsynchRX( &amp;MyDemoCallback ); // ERROR ON THIS LINE } </code></pre> <p>1>......\Src\Support\AR2500 Commissioning\Main.cpp(99): error C2664: 'ocular::DeviceClass::StartAsynchRX' : cannot convert parameter 1 from 'DemoCallbackClass (__cdecl *)(void)' to 'ocular::DeviceCallback *'</p> <p>I'm reasonably sure I've done something silly here, but I can't find it for the life of me. Last week I wrote an event timer class using exactly the same approach and it works just fine. If the structure/approach looks OK to everyone out there, I guess It's a subtle typo, and I just need to rewrite a chunk at a time until I get rid of the damn error.</p> <p>Yours in desparation,</p> <p>DKW</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload