Classes Callback problems , Delegate

my delegate.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef __DELEGATE_HPP__
#define __DELEGATE_HPP__

class Callback
{
    virtual void Call(void* indata);
};

template <class T>
class Delegate : public Callback
{
    void (T::*func)(void*);
    T* This;
public:
    
    Delegate() 
    {
		func = 0;
		This = 0;
	}

    void Set(void (T::*infunc)(void*), T* inthis)
    {
        func = infunc;
        This = inthis;
    }

    void Call(void* indata)
    {
        This->*func(indata);
    }
};

#endif 


my sample code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "delegate.hpp"

class Test
{
	Delegate<Test> dmethod;
public:
	Test()
	{
		dmethod.Set(&Test::method, this);
	}
	
	void method(void* data)
	{
		
	}
};


int main()
{
	Test testing;
	
	return 0;
}


Errors

delegate.hpp: In instantiation of ‘void Delegate<T>::Call(void*) [with T = Test]’:
delegateTest.cpp:25:1: required from here
delegate.hpp:30:9: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((Delegate<Test>*)this)->Delegate<Test>::func (...)’, e.g. ‘(... ->* ((Delegate<Test>*)this)->Delegate<Test>::func) (...)’
line 30 of delegate.hpp: (This ->* func)(indata);//If you don't know you cannot have space between -> and *, because you should use operator ->* here.
It will give you
undefined reference to `vtable for Callback'|
. To get rid of that you should define your Callback::Call() function ( or do virtual void Call(void* indata) = 0;)
Last edited on
Topic archived. No new replies allowed.