voidf(intx)
{
}
void main()
[
void(*p)();
p=f
}
uj5u.com熱心網友回復:
p被定義成一個無引數無回傳的函式指標而f是有 個引數的,能通過編譯,但是呼叫的時候,你怎么呼叫呢?
uj5u.com熱心網友回復:
該有的空格、分號、中英文括號、中括號uj5u.com熱心網友回復:
#include <tchar.h>
#include <iostream>
//---------------------------------------------------------------------------
#pragma argsused
using namespace std;
void f(int xx)
{
//cout << "x = " << xx << endl;
cout << "f(int x) called..." << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
void (*p)();
p = (void (*)())f; //強制轉換為無型別
p();
system("PAUSE");
return 0;
}
//---------------------------------------------------------------------------
uj5u.com熱心網友回復:
強制轉移為無參函式或采用定義與呼叫一致的函式。C++對函式名的處理與C不同。void f(int xx)的函式名將被編譯器處理為void f_xx()以區別多載函式。//---------------------------------------------------------------------------
#pragma hdrstop
#include <tchar.h>
#include <iostream>
//---------------------------------------------------------------------------
#pragma argsused
using namespace std;
void f(int xx)
{
cout << "x = " << xx << endl;
cout << "f(int x) called..." << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
void (*p)(int x);
p = f;
p(1010);
system("PAUSE");
return 0;
}
//---------------------------------------------------------------------------
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/83386.html
標籤:基礎類
上一篇:求問這該段代碼的時間復雜度
