S
sojalvo
Hi,
I'm porting a project from Win32 to Linux(debian) and I found a problem
using interfaces.
For simplify the question, I created a small test and here is the code:
#include <stdio.h>
#define interface struct
interface ITest
{
virtual int printHello() = 0;
protected:
virtual ~ITest(){};
};
class CTest : public ITest
{
public:
CTest(){ }
virtual ~CTest() { }
private:
//ITest Interface
int printHello() { printf("Hello\n"); }
};
class CGetter
{
public:
CGetter() { test = new CTest; }
~CGetter() { delete test; }
void getTestPtr(const ITest*& t) const;
private:
CTest * test;
};
void CGetter::getTestPtr(const ITest*& t) const
{
t = test;
return;
}
int main( int argc, char *argv[] )
{
ITest * it;
CGetter g;
g.getTestPtr((const ITest*) it);
it->printHello();
return 0;
}
The problem is with the "it" pointer in main.
Debugging the CGetter::getTestPtr() fnc. I can see:
"test" pointer address = (CTest *) 0x8049c20
after a assignment,
"t" pointer address = (const ITest *&) @0xbffff88c: 0x8049c20
and back in main,
"it" pointer address points to: (ITest *) 0x4023f620
causing segmentation fault.
In Win32 this test works... Any Idea?
Thanks,
I'm porting a project from Win32 to Linux(debian) and I found a problem
using interfaces.
For simplify the question, I created a small test and here is the code:
#include <stdio.h>
#define interface struct
interface ITest
{
virtual int printHello() = 0;
protected:
virtual ~ITest(){};
};
class CTest : public ITest
{
public:
CTest(){ }
virtual ~CTest() { }
private:
//ITest Interface
int printHello() { printf("Hello\n"); }
};
class CGetter
{
public:
CGetter() { test = new CTest; }
~CGetter() { delete test; }
void getTestPtr(const ITest*& t) const;
private:
CTest * test;
};
void CGetter::getTestPtr(const ITest*& t) const
{
t = test;
return;
}
int main( int argc, char *argv[] )
{
ITest * it;
CGetter g;
g.getTestPtr((const ITest*) it);
it->printHello();
return 0;
}
The problem is with the "it" pointer in main.
Debugging the CGetter::getTestPtr() fnc. I can see:
"test" pointer address = (CTest *) 0x8049c20
after a assignment,
"t" pointer address = (const ITest *&) @0xbffff88c: 0x8049c20
and back in main,
"it" pointer address points to: (ITest *) 0x4023f620
causing segmentation fault.
In Win32 this test works... Any Idea?
Thanks,