64,281
社区成员
发帖
与我相关
我的任务
分享
//#include "stdafx.h"
#include "stdio.h"
void fun(test); //函数声明,这里要用到test类的参数
//[!!]由于某些特殊原因,fun必须作为外部函数而不能作为test的成员函数!!
class test{ //类声明
public:
int a;
void (*v)(void); //函数指针.
test(){
v = fun;
}
};
void fun(test t){
t.a=1;
}
int main(){
test tt;
fun(tt);
return 0;
}
#include "stdafx.h"
#include "stdio.h"
//void fun(test);
class test{
public:
int a;
friend void fun(test); //函数指针.
test(){
printf("hello!\n");
}
};
void fun(test t){
t.a=1;
}
int main(){
test tt;
fun(tt);
return 0;
}
#include<iostream>
using namespace std;
class test;
void fun(test); //函数声明,这里要用到test类的参数
class test{ //类声明
public:
int a;
void (*v)(test); //函数指针.
test(){
v = fun;
}
};
void fun(test t){
t.a=1;
}
int main(){
test tt;
fun(tt);
system("pause");
return 0;
}