Array type xxx is not assignable
問題
在 world_type.h裡面的struct。species_t也是一個struct。
struct world_t
{
unsigned int numSpecies;
species_t species[MAXSPECIES];
unsigned int numCreatures;
creature_t creatures[MAXCREATURES];
grid_t grid;
};
試圖 initialize 一個 world_t world 的 species 陣列,但是報錯 ”Array type ‘species_t [10]’ is not assignable“
world = {(unsigned)numSpecies};
world.species = species;
原因
上面的程式碼中,我嘗試將species陣列賦值給world的species。但是在C++中,不能利用等式給陣列賦值。只能逐個給陣列的element賦值。
解決方案
world = {(unsigned)numSpecies};
for(int i = 0; i < numSpecies; i++){
world.species[i] = species[i];
}
相關文章
- xxx cannot be resolved to a type
- type[xxx]的用法
- error: ‘xxx’ does not name a typeError
- QT中error: xxx does not name a type xxx錯誤QTError
- vue Cannot find module @/xxx/xxx.ts or its corresponding typeVue
- 解決Tensorflow ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)ErrorAIObject
- could not connect to redis Instance at xxx.xxx.xxx.xxx:6379Redis
- C++ vector<std::tuple<XXX, XXX, XXX>>C++
- webstorm vue3+ts報錯:Cannot find module ‘@/views/xxx.vue‘ or its corresponding type declarationsWebORMVueView
- cannot convert (type interface {}) to type int: need type assertion
- Linux虛擬機器配置IP時提示:determining ip information for ip xxx.xxx.xxx.xxx address is alreadyLinux虛擬機ORM
- Permission denied:user=xxx,access=WRITE,inode=xxx
- Array.from和 Array.of
- array
- PHP用foreach來表達array_walk/array_filter/array_map/array_reducePHPFilter
- Array()與Array.of()方法區別
- JS Array.reduce 實現 Array.map 和 Array.filterJSFilter
- HITSC_4_Data Type and Type Checking
- Unable to negotiate with xx.xxx.xxxx port 22: no matching host key type found. Their offer: ssh-rsa(解決的兩種方式)Go
- array_filter ()、array_map ()、array_walk () 區別?容易記混淆!!!Filter
- No instances available for XXXAI
- Array物件物件
- Array Repetition
- Unique Array
- Array Division
- 搭建 docker registry 私有倉庫並解決報錯Get https://xxx.xxx.xxx.xxx:5000/v1/_ping: http: server gave HTTP respDockerHTTPServer
- zsh:command not found: xxx
- No bean named ''XXX“ availableBeanAI
- J2SE - Could not find the main class: xxx.xxx.Program will exitAI
- Result Maps collection already contains value for xxx.xxx.dao.BaseResultMap錯誤AI
- network xxx was found but has incorrect label com.docker.compose.network set to "xxx"Docker
- JavaScript Array 物件JavaScript物件
- array_chunk
- Array.from()
- JavaScript Array物件JavaScript物件
- Leetcode Sort ArrayLeetCode
- Sort Array By Parity
- Array陣列陣列