/***一般函数情况****/
#include <iostream>
#include <string>
using namespace std;
void function1(string& x)
{
cout<<x;
}
void function2(string& x)
{
cout<<x<<endl;
}
void Test(void(*p)(string& y),string& z)
{
cout<<"this is a test"<<endl;
p(z);
}
int main()
{
string x("welcome!");
Test(function1,x);
system("pause");
}
#include <string>
using namespace std;
void function1(string& x)
{
cout<<x;
}
void function2(string& x)
{
cout<<x<<endl;
}
void Test(void(*p)(string& y),string& z)
{
cout<<"this is a test"<<endl;
p(z);
}
int main()
{
string x("welcome!");
Test(function1,x);
system("pause");
}
/******成员函数情况********/
#include <iostream>
using namespace std;
class B
{
public :
double funB(double a){return a;};
};
class C
{
public :
double funC(double a){return a;};
};
class A
{
public :
template <typename T>
double funA(double (T::*func)(double),T t,double a){return (t.*func)(a);};
};
int main()
{
A a;
B b;
double dParam = 3.0;
using namespace std;
class B
{
public :
double funB(double a){return a;};
};
class C
{
public :
double funC(double a){return a;};
};
class A
{
public :
template <typename T>
double funA(double (T::*func)(double),T t,double a){return (t.*func)(a);};
};
int main()
{
A a;
B b;
double dParam = 3.0;
cout < <a.funA(&B::funB,b,dParam) < <endl;
return 0 ;
}
//或者
class base
{
vitual double funA()=0; \\纯虚函数 (如果你在b类 C类等其它类的实现功能不一样的话
} ;
也可以这样:
class base
{
double funB(double){//如果你在其它类中的功能都是一样的话
//函数体
}
} ;
class a:public base
{
.
.
.
};
class b:public base
{
.
.
.
};