c++ static cast with .so loading at run-time
<p>I'm trying to load a shared object (<code>SensorTemp</code> derived class) at runtime using the dlopen() API. When I try to static-case the pointer to the appropriate function pointer, I get</p>

<pre><code>LinkTest.cpp:26:48: error: invalid static_cast from type ‘void*’ to type ‘Sensor*()’
Sensor* mySensor = static_cast&lt;Sensor *()&gt;(mkr)(myHub, a, b, c, d, e);
</code></pre>

<p>Here's the relevant <code>Sensor.h</code> base class constructor:</p>

<pre><code>class Sensor
{
public:
    Sensor(Hub&amp; _pHub, const std::string&amp; _name, const std::string&amp; _type, const std::string&amp; _logLevel, const std::string&amp; _configInfo, const std::string&amp; _location): m_pHub(&amp;_pHub), m_name(_name), m_type(_type), m_logLevel(_logLevel), m_configInfo(_configInfo), m_location(_location) {}
</code></pre>

<p>Derived class <code>SensorTemp.h</code> : (its CTOR calls the base CTOR)</p>

<pre><code>#include "Sensor.h"

class SensorTemp : public Sensor
{
public:
    SensorTemp(Hub&amp; _pHub,  const std::string&amp; _name, 
                            const std::string&amp; _type, 
                            const std::string&amp; _logLevel, 
                            const std::string&amp; _configInfo, 
                            const std::string&amp; _location);
    ~SensorTemp() {}
    void* Run();
private:
    int m_lowTemp;
    int m_highTemp;
    int m_interval;
};

extern "C"
{
    SensorTemp* Create(Hub&amp; _pHub,  const std::string&amp; _name, 
                                    const std::string&amp; _type, 
                                    const std::string&amp; _logLevel, 
                                    const std::string&amp; _configInfo, 
                                    const std::string&amp; _location)
    {
        return new SensorTemp(_pHub, _name, _type, _logLevel, _configInfo, _location);
    }

}

#endif //__SENSORTEMP_H__
</code></pre>

<p>the test:</p>

<pre><code>int main(int argc, char **argv)
{
    Hub myHub;
    string a = "A";
    string b = "B";
    string c = "C";
    string d = "D";
    string e = "E";
    string f = "F";
    void *hndl = dlopen("./libSensorTemp.so", RTLD_LAZY);
    if(hndl == NULL)
    {
       std::cerr &lt;&lt; dlerror() &lt;&lt; std::endl;
       exit(-1);
    }
    void *mkr = (Sensor*)dlsym(hndl, "Create");
    Sensor* mySensor = static_cast&lt;Sensor *()&gt;(mkr)(myHub, a, b, c, d, e);
    mySensor-&gt;Run();

}
</code></pre>