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: 'cout' does not name a type|Error
- error: ‘xxx’ does not name a typeError
- Qt 報錯 “類名”does not name a typeQT
- QT中error: xxx does not name a type xxx錯誤QTError
- ‘map’ does not name a type
- does not name a type 的可能性
- PSQLexception: ERROR : type "signed" does not existSQLExceptionError
- eclipse :報錯 ‘XXXX‘ does not name a type的解決辦法Eclipse
- Android之NDK開發錯誤 error: unknown type name 'JNIEXPORT'AndroidErrorExport
- Property 'context' does not exist on type 'NodeRequire'.ts(2339)ContextUI
- editor does not contain a main type Maven專案AIMaven
- Error creating bean with name 'tomcatEmbeddedServletContainerFactory'ErrorBeanTomcatServletAI
- Error creating bean with name ‘dataSource‘ErrorBean
- grep: PCRE does not support L, l, N{name}, U, or u
- Error-Expected resource of typeError
- Caused by: Error: ' ' is not a valid resource name characterError
- Error creating bean with name 解決ErrorBean
- Rust的變數型別__Data typeRust變數型別
- c++ typeid().name()輸出變數型別C++變數型別
- dcat-admin 表單 Field type [autocomplete] does not exist.
- 通俗易懂解釋一類和二類錯誤(Type I Error Type II Error)Error
- Error: --recode does not support multipass recoding of very large files.Error
- Error message Object BOM does not allow filter on MAST.STLNRErrorObjectFilterAST
- ORA-30012 undo tablespace 'UNDOTBS3' does not exist or of wrong typeS3
- MySQL中的@變數名MySql變數
- 變數名命名規則變數
- Import Error: cannot import name ‘export_saved_modelImportErrorExport
- TypeScript type 型別別名TypeScript型別
- ERROR: failed to establish dependency between database db_name and diskgroupErrorAIDatabase
- Error creating bean with name ‘dataSource‘: Unsatisfied dependency expressed through fieldErrorBeanExpress
- 問題No property 屬性名 found for type 類名
- _error-type_cout_不明確的符號Error符號
- error: invalid type argument of unary ‘*‘ (have ‘int‘) *__first = __tmp;Error
- Python學習筆記|Python之內建變數__name__Python筆記變數
- mysql 5.7.21 CMake Error: The source directory "/data/server/mysql" does not appear to contain CMakMySqlErrorServerAPPAI
- SAP MRKO Error - For document type RE, an entry is required in field Reference -ErrorUI
- 給出 Python 中變數名的列表,如何建立一個具有變數名稱作為鍵的字典 (到變數的值)Python變數
- 求大家幫助,Jmeter 變數為 null 時,輸出的是變數名,如何不輸出變數名原樣輸出 null?JMeter變數Null