#include<stdio.h>
class A
{ public:
void f(int a)
{
a = 5;
}
};
//void f1() //1 全局函数
//{
// int b=3;
// int a = 3;
// A::f(a); //error 未定义f 非静态成员引用必须与特定对象相对
//
// printf("%d\n", b + a);
//}
void f1() //2 全局函数
{
int b = 3;
int a = 3;
A t;
t.f(a);
printf("%d\n", b +a);
}
int main()
{
f1();
return 0;
class A
{ public:
void f(int a)
{
a = 5;
}
};
//void f1() //1 全局函数
//{
// int b=3;
// int a = 3;
// A::f(a); //error 未定义f 非静态成员引用必须与特定对象相对
//
// printf("%d\n", b + a);
//}
void f1() //2 全局函数
{
int b = 3;
int a = 3;
A t;
t.f(a);
printf("%d\n", b +a);
}
int main()
{
f1();
return 0;
}
//1错误 2正确 所以 全局函数调用成员函数时候必须声明对象然后通过对象调用呀。:cannot call member function 'void MainWindow::timeClicked(QTime)' without object
If you want to call them like that, you should declare them static.
http://stackoverflow.com/questions/1127738/cannot-call-member-function-without-object