rk
2011-08-12 19:31:27 UTC
Hi,
I have run into similar problems before and have used convoluted
strategies to resolve the issue. This time I want to undertand this
problem better. I have the following scenario.
My dll has the files A.cpp, B.hpp and someother_file.cpp
/// A.hpp
EXPORT_CLASS class A : public B
{
public:
static const char *flag_;
virtual const char* flag() { return A::flag_; }
}
/// B.hpp
EXPORT_CLASS class B
{
public:
virtual const char * flag() = 0;
}
///// somother_file.cpp
#include "A.hpp"
void test(B& b)
{
if( b->flag() == A::flag_ )
{
//// Do something...
}
}
/// main.cpp
#include <factory.hpp>
int main(int argc, char *argv[])
{
B* b = factory_create_a();
test(*b);
}
The issue is that the condition b->flag() == A::flag_ fails. I have
looked at the dissasembly and the addresses being compared are
different, i.e. b->flag() returns ad different address than A::flag_.
It would be great to get an Idea of what is going on here?
I have run into similar problems before and have used convoluted
strategies to resolve the issue. This time I want to undertand this
problem better. I have the following scenario.
My dll has the files A.cpp, B.hpp and someother_file.cpp
/// A.hpp
EXPORT_CLASS class A : public B
{
public:
static const char *flag_;
virtual const char* flag() { return A::flag_; }
}
/// B.hpp
EXPORT_CLASS class B
{
public:
virtual const char * flag() = 0;
}
///// somother_file.cpp
#include "A.hpp"
void test(B& b)
{
if( b->flag() == A::flag_ )
{
//// Do something...
}
}
/// main.cpp
#include <factory.hpp>
int main(int argc, char *argv[])
{
B* b = factory_create_a();
test(*b);
}
The issue is that the condition b->flag() == A::flag_ fails. I have
looked at the dissasembly and the addresses being compared are
different, i.e. b->flag() returns ad different address than A::flag_.
It would be great to get an Idea of what is going on here?