QA@IT
«回答へ戻る

回答を投稿

reinterpret_castを使うのはどうでしょうか:

class CBase
{
public:
    virtual void fn() = 0;
};

class C1 : public CBase
{
public:
    void fn() {}
};

class Hoge
{
public:
    C1 member1;
};

int main(int argc, char *argv[])
{
    CBase Hoge::*pm1 = reinterpret_cast<CBase Hoge::*>(&Hoge::member1);

    Hoge hoge;
    (&hoge->*pm1).fn();

    return 0;
}
reinterpret_castを使うのはどうでしょうか:

```c++
class CBase
{
public:
	virtual void fn() = 0;
};

class C1 : public CBase
{
public:
	void fn() {}
};

class Hoge
{
public:
	C1 member1;
};

int main(int argc, char *argv[])
{
	CBase Hoge::*pm1 = reinterpret_cast<CBase Hoge::*>(&Hoge::member1);

	Hoge hoge;
	(&hoge->*pm1).fn();

	return 0;
}
```