Portál AbcLinuxu, 13. května 2025 23:06
void* ptr = &NazevTridy::NazevMetodynejde?
#include<iostream> class Test { typedef void (Test::*fp)(int) const; fp func; public: void test1(int a) const { std::cout << 10*a << std::endl; } void test2(int a) const { std::cout << 10 + a << std::endl; } void init(fp f) { func = f; } void call(int a) const { (this->*func)(a); } }; int main() { Test t; t.init(&Test::test1); t.call(11); t.init(&Test::test2); t.call(11); return 0; }
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.