Home Understanding about templates and function pointer
Reply: 0

Understanding about templates and function pointer

user774
1#
user774 Published in April 27, 2018, 6:53 am

I would like to know Why have to make fun1() as static member function? function pointer in template? in below piece of code.

#include<iostream>
using namespace std;
class A
{
    int temp;
    public:
    A():temp(1){}
    template<class T, void (*fn)(T* )>
    static void create(T *ptr)
    {
        cout <<"create fn"<<endl;
        //fun1(ptr);
    }
    static void fun1(A* tp) 
    {
         cout<<"func temp"<<endl;
    }
    static void fun2(A& ob)
    {
        cout<<"fun2 start"<<endl;
        A::create<A,&A::fun1>(&ob);
        cout<<"fun2 end"<<endl;
    }
};
int main()
{
    A ob,ob1;
    ob.fun2(ob1);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316938 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO