Skip to content

Commit 424e556

Browse files
committed
Fix CVirtualTable constructor & method
1 parent 037a373 commit 424e556

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

include/dynlibutils/virtual.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include <cstddef>
11+
1012
namespace DynLibUtils {
1113

1214
class CVirtualTable
@@ -16,14 +18,14 @@ class CVirtualTable
1618

1719
public: // Constructors.
1820
CVirtualTable() : m_pVTFs(nullptr) {}
19-
template<class T> CVirtualTable(T *pClass) : m_pVTFs(reinterpret_cast<void **>(pClass)) {}
21+
template<class T> CVirtualTable(T *pClass) : m_pVTFs(*reinterpret_cast<void ***>(pClass)) {}
2022

2123
public: // Getters.
2224
template<typename R> R &GetMethod(std::ptrdiff_t nIndex) { return reinterpret_cast<R &>(m_pVTFs[nIndex]); }
2325
template<typename R> R GetMethod(std::ptrdiff_t nIndex) const { return reinterpret_cast<R>(m_pVTFs[nIndex]); }
2426

2527
public: // Callers.
26-
template<typename R, typename... Args> R CallMethod(std::ptrdiff_t nIndex, Args... args) { return GetMethod<R (*)(void *, Args...)>(nIndex)(m_pVTFs, args...); }
28+
template<typename R, typename... Args> R CallMethod(std::ptrdiff_t nIndex, Args... args) { return GetMethod<R (*)(void *, Args...)>(nIndex)(this, args...); }
2729
template<typename R, typename... Args> R CallMethod(std::ptrdiff_t nIndex, Args... args) const { return const_cast<CThis *>(this)->CallMethod(nIndex, args...); }
2830

2931
void **m_pVTFs;

0 commit comments

Comments
 (0)