views:

83

answers:

1

I have three classes: Generic, CFG, and Evaluator.

Here's Generic:

class Generic: public virtual Evaluator, public CFG, public LCDInterface {

Here's CFG:

class CFG : public virtual Evaluator {

And Evaluator subclasses nothing.

I'm providing a DLL named PluginLCD, and it has a method called Connect:

void PluginLCD::Connect(Evaluator *visitor) {
    visitor_ = dynamic_cast<Generic *>(visitor);
    if(!visitor_)
        return;
    type_ = visitor_->GetType();
}

Here's how I'm compiling the DLL through scons:

env.SharedLibrary(['PluginLCD.cpp', 'Evaluator.cpp', 'Generic.cpp', 'CFG.cpp'])

Now, there are two scenarios in my code. One is in class LCDControl, which subclasses CFG. The other scenario is above where Generic subclasses Evaluator and CFG. Evaluator has a method called LoadPlugins, which does what its name suggests, passing this through to the DLL via method Connect. Well, in the first scenario the cast to Generic * in Connect should return NULL. However, in the second scenario, as far as I know, a valid pointer should be returned. It doesn't seem to be happening this way. Am I wrong about this?

+2  A: 

dynamic_cast is known to break across module boundaries with many compilers (including MSVC and gcc). I don't know exactly why that is, but googling for it yields many hits. I'd recommend trying to get rid of the dynamic_cast in the first place instead of trying to find out why it returns null in your second scenario.

Frerich Raabe
Turns out I forgot a few source files in the compilation of the DLL. I did as you suggested and tossed the idea of making PluginLCD a DLL and hardcoded it into the program. It doesn't need to be in scenario 1 at all anyways.
Scott