![](/img/trans.png)
[英]main.cpp|34|error: 'putere' was not declared in this scope| [and also verif_polim (functions)]
[英]main.cpp:22:34: error: ‘xxxxxxx’ was not declared in this > scope
我遇到此錯誤:
main.cpp:22:34:錯誤:未在此范圍內聲明'getTotalSystemMemory'
#include <unistd.h>
#include <cstdlib>
#include <stdio.h>
#include <iostream>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
cout << "Hello World! \n";
cout << getTotalSystemMemory();
return 0;
}
long getTotalSystemMemory()
{
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
}
我假設方法“ getTotalSystemMemory”在范圍內,因為它在同一類中
使用該函數之前,您至少需要提供一個聲明 :
long getTotalSystemMemory(); //declaration
int main(int argc, char** argv) {
//...
cout << getTotalSystemMemory();
//...
}
long getTotalSystemMemory()
{
//...
}
您必須先使用C / C ++聲明該函數。
把這個放在main
long getTotalSystemMemory();
如果要在int main() {}
下定義函數,則必須“原型化”該函數:
long getTotalSystemMemory();
int main() {
/* ....... */
getTotalSystemMemory();
}
long getTotalSystemMemory() {}
在c ++中,必須在使用該函數的函數之前編寫該函數。
before. 如果您不想在頂部編寫該函數,則必須先放置一個 。 原型看起來像這樣:
<return-value> <function name> (<parameters type>);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.