utmemberfun.cc

来自「C++ Reflection & Service Library」· CC 代码 · 共 76 行

CC
76
字号
/* C++ Reflection & Serice Library * Copyright (C) 2003  Marcus Perlick * mailto: riffraff@users.sf.net *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * * This file is part of the "C++ Reflection & Serice Library" */#include <cstdlib>#include <iostream>#include <rfl/Exception.hh>#include <rfl/FundamentalType.hh>#include <rfl/PointerType.hh>#include <rfl/CClassType.hh>#include <rfl/CFunctionType.hh>struct Foo {  int i, j;  int f( std::ostream& os );};int Foo::f( std::ostream& os ){  os << "( " << i << ", " << j << " )" << std::endl;  i = (i + j) / 2;  j = rand() % 100;  return i;}int main( int argc, char* argv[] ){  int rc = 0;  try {    Foo foo = { 47, 11 };    rfl::CClassType<std::ostream> stdOstreamType( "std::ostream",						  0, 0, 0, 0, 0, 0, 0 );    rfl::PointerType stdOstreamPtrType( stdOstreamType );    rfl::CClassType<Foo> fooType( "Foo",				  0, 0, 0, 0, 0, 0, 0 );    rfl::PointerType fooPtrType( fooType );    rfl::CFunctionType mbrFunType( rfl::TypeInt );    mbrFunType.addArg( fooPtrType );    mbrFunType.addArg( stdOstreamPtrType );    typedef void(*FooFunPtr)(Foo*);    FooFunPtr fooFun = (FooFunPtr)(foo.*&Foo::f);    std::ostream* coutPtr = &std::cout;    Foo* fooPtr = &foo;    int result;    mbrFunType.vaCall( &result, (void*)fooFun, &fooPtr, &coutPtr );    std::cout << "Result = " << result << std::endl;  }  catch ( rfl::Exception x ) {    rc = 1;    std::cerr << x << std::endl;  }  return rc;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?