本文整理汇总了C++中Method::invoke方法的典型用法代码示例。如果您正苦于以下问题:C++ Method::invoke方法的具体用法?C++ Method::invoke怎么用?C++ Method::invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Method
的用法示例。
在下文中一共展示了Method::invoke方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: methodTest
bool methodTest() {
Class A(NULL, "A");
Class B(&A, "B");
ASSERT_NO_THROW(B.addMethod("nothing", doesNothing));
ASSERT_EQUALS("nothing", B.getMethod("nothing").name());
ASSERT_EQUALS("B", B.getMethod("nothing").getDeclaringClass());
Method m = B.getMethod("nothing");
Object* inst = A.newInstance();
Object* b_inst = B.newInstance();
ASSERT_THROW(MethodNotFound, m.invoke(inst));
ASSERT_NO_THROW(m.invoke(b_inst));
ASSERT_NO_THROW(A.addInstanceField("x", INT));
// set accessible must be zero but invoke must succeed
ASSERT_NO_THROW(A.addMethod("goblin", goblinIsHere));
Object* obj = A.newInstance();
Field f = A.getField("x");
Class::setAccessible(true);
ASSERT_EQUALS(f.getInt(obj), 0);
Class::setAccessible(false);
ASSERT_NO_THROW(obj->invokeMethod("goblin"));
ASSERT_THROW(FieldNotAccessible, f.getInt(obj));
Class::setAccessible(true);
ASSERT_EQUALS(f.getInt(obj), 7);
/* delete inst;
delete b_inst;
delete obj;*/
return true;
}
示例2:
SmokeObject *SmokeObject::convertImplicitly(const SmokeType &type) const {
const Class *cl = Class::fromSmokeId(type.smoke(), type.classId());
Method *meth = cl->findImplicitConverter(this);
SmokeObject *converted = NULL;
if (meth) {
Smoke::StackItem stack[2];
stack[1].s_voidp = _ptr;
meth->invoke(NULL, stack);
if (meth->lastError() == Method::NoError)
converted = SmokeObject::fromPtr(stack[0].s_voidp, type, true);
delete meth;
}
return converted;
}
示例3: invokeMethod
void Object::invokeMethod(std::string name) {
Class* myClass = this->getClass();
Method method = myClass->getMethod(name);
method.invoke(this);
}