error: ‘變數名‘ does not name a type|
寫了個標頭檔案
程式碼大概這樣
int *tasks;
int *nodes;
//初始化任務集合
mt19937 rng;
tasks=new int[taskNum];
for(int aa=0;aa<taskNum;aa++){
std::uniform_int_distribution<int> dis1(10,100);
tasks[aa]=dis1(rng);
}
nodes=new int[nodeNum];
for(int i=0;i<nodeNum;i++){
std::uniform_int_distribution<int> dis1(10,100);
nodes[i]=dis1(rng);
}
其中tasks、aa、nodes、i這些變數都報錯。
後來看文章給出的解釋,說main函式外不能這樣賦值?具體原因也不明白,解決辦法就是將這塊程式碼寫進某個函式中。
像這樣
void initialTasksAndNodes() {
mt19937 rng;
//初始化任務集合
tasks=new int[taskNum];
for(int aa=0; aa<taskNum; aa++) {
std::uniform_int_distribution<int> dis1(10,100);
tasks[aa]=dis1(rng);
}
nodes=new int[nodeNum];
for(int i=0; i<nodeNum; i++) {
std::uniform_int_distribution<int> dis1(10,100);
nodes[i]=dis1(rng);
}
}
這個錯就不報了。
相關文章
- error :does not name a typeError
- error: '[class name]' does not name a typeError
- error: 'cout' does not name a type|Error
- error: ‘xxx’ does not name a typeError
- Qt 報錯 “類名”does not name a typeQT
- ‘map’ does not name a type
- vector does not name a type
- ndk編譯錯誤:error: 'override' does not name a type編譯ErrorIDE
- does not name a type 的可能性
- 'int32_t' does not name a type
- QT中error: xxx does not name a type xxx錯誤QTError
- `QtValidLicenseForCoreModule' does not name a type 錯誤的解決QTREM
- PSQLexception: ERROR : type "signed" does not existSQLExceptionError
- 編譯錯誤 --- does not name a type和field `XX' has incomplete type編譯
- 編譯錯誤--------:XX does not name a type和field `XX' has incomplete type編譯
- Qt 標頭檔案互相包含會報錯'' does not name a typeQT
- 兩個C++編譯錯誤及解決辦法--does not name a type和field `XX' has incomplete typeC++編譯
- Android之NDK開發錯誤 error: unknown type name 'JNIEXPORT'AndroidErrorExport
- eclipse :報錯 ‘XXXX‘ does not name a type的解決辦法Eclipse
- Oracle中的替換變數,&變數名,&&變數名說明Oracle變數
- A resource type with the name 'ora.daemon.type' is already registered
- C++ doesn't name a typeC++
- Rust的變數型別__Data typeRust變數型別
- PHP的可變變數名PHP變數
- editor does not contain a main type Maven專案AIMaven
- Error-Expected resource of typeError
- 解剖Nginx·自動指令碼篇(6)編譯器名稱變數指令碼 auto/cc/nameNginx指令碼編譯變數
- 變數名命名規則變數
- SNMP TABLE ERROR : Requested table is empty or does not existError
- c++ typeid().name()輸出變數型別C++變數型別
- Caused by: Error: ' ' is not a valid resource name characterError
- Error creating bean with name ‘dataSource‘ErrorBean
- emulator: ERROR: unknown virtual device nameErrordev
- Property 'context' does not exist on type 'NodeRequire'.ts(2339)ContextUI
- 編譯錯誤導致浪費10多分鐘, 編譯錯誤的提示:xxx does not name a type xxx編譯
- 通俗易懂解釋一類和二類錯誤(Type I Error Type II Error)Error
- error:dereferencing pointer to incomplete typeError
- TypeScript type 型別別名TypeScript型別