[問題] 呼叫class函數與int

作者: ComputerGod (電資雙雄)   2015-03-05 15:46:21
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux GCC
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
NO
問題(Question):
#include <cstdlib>
#include <iostream>
using namespace std;
int VDR = 3000;
void SetVR()
{
VDR =VDR -100;
APP->dec(5,4);
}
class APP
{
public:
void dec(int x, int y);
};
void dec(int x,int y)
{
int d = x-y;
cout << d << endl;
}
int main()
{
SetVR();
cout << VDR <<endl;
system("pause");
return 0;
}
預期的正確結果(Expected Output):
2900
1
錯誤結果(Wrong Output):
APP was not declared in this scope
不曉得如何處理?
我已經是使用public為何外部抓不到
作者: LPH66 (-6.2598534e+18f)   2015-03-05 16:23:00
把 class APP 拉到 SetVR 上面
作者: NilPtr (神奇的空指標)   2015-03-05 21:31:00
樓上大大已解 補充下 函數上面補上 class APP; 也可以因為C++編譯器一定要先看到定義或宣告某類別存在 才准用不過還有2個問題 ... 等等補完二樓我說的是錯的 當我沒說過 XD剩下兩個問題 1.C++物件呼叫函數要有實例化物件才可用2.在Class外面實作Member一定要在函數名前頭加上Class名void APP::dec(int x,int y) {...} 才對

Links booklink

Contact Us: admin [ a t ] ucptt.com