AngelScript 메서드를 '래핑하는'클래스가 있습니다. 기본적으로 클래스, 메소드 리턴 유형, 메소드에 대한 포인터 및 인수 목록을 보냅니다.C++ 임베디드 템플릿 템플릿
지금까지 매개 변수를 사용하지 않는 클래스 메서드를 '바인딩'할 때까지이 객체를 성공적으로 만들 수있었습니다. Method
그러나 매개 변수를 추가하려고하면 중단됩니다.
template<typename C, typename R, R (C::*fn)(), typename... Arguments>
class Method {
public:
Method()
{
const asSFuncPtr& func = asSMethodPtr<sizeof(void (C::*)())>::Convert(AS_METHOD_AMBIGUITY_CAST(R (C::*)(Arguments... parameters)) (fn));
function = &func;
};
virtual ~Method(){};
const asSFuncPtr* function;
};
struct S
{
int f()
{
return 5;
}
int f(int a)
{
return a + 1;
}
};
을 그리고 다음과 같이 내 Method
객체를 생성 :
나는 이런 식으로 뭔가를하고있는 중이 야
Method<S, int, &S::f> m = Method<S, int, &S::f>();
이 작동합니다.
그러나,이 같은 방법 개체를 만들려고하는 경우 :
Method<S, int, &S::f, int> m2 = Method<S, int, &S::f, int>();
그것은이 메시지와 함께 나누기 : 나는에 대한 포인터를 전달하고있어 이후,
template_tests.cpp: In instantiation of ‘Method<C, R, fn, Arguments>::Method() [with C = S; R = int; R (C::* fn)() = &S::f; Arguments = {int}]’:
template_tests.cpp:74:61: required from here
template_tests.cpp:27:142: error: invalid static_cast from type ‘int (S::*)()’ to type ‘int (S::*)(int)’
의미가 있습니다 함수는 매개 변수가 없습니다.
이제 매개 변수 수가 다른 클래스 메서드에 대한 메서드 포인터를 받아들이도록 Method
클래스를 어떻게 변경합니까? - 나는 내부 가변 인자 템플릿을 '포함'어떻게
template<typename C, typename R, R (C::*fn)(Arguments... parameters), typename... Arguments>
class Method {
...
}
그 일을하는 것은 오류가 모든 종류의 원인이되기 때문에 .. 기본적으로
, 내가 부탁 해요 추측 :
내가 이런 일을합니까 템플릿 템플릿? 이것이 가능한가?
정말로 인수가 필요하고 유형을 따로 반환해야합니까? 만약'Method'가'template class Method'와 같은 것이고'Method
'처럼 사용된다면 어떨까요? –