我只是想创建以下类:
class model
{
public:
.
.
.
unordered_map<string, material> materials;
.
.
.
}
注释此行程序后,编译成功。取消注释后会产生以下错误:
In file included from glmw1.cpp:1:
In file included from ./global.hpp:3:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/ccomplex:39:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/complex:45:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/sstream:38:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/istream:38:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/ios:40:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/bits/char_traits.h:39:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/bits/stl_algobase.h:64:
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../include/c++/9.2.0/bits/stl_pair.h:215:11: error: field has incomplete type 'material'
_T2 second; /// @c second is a copy of the second object
.
.
.
材料只是普通的类。我还在程序中声明了一些“模型”类型的对象(如果有区别的话)
您需要提供材质对象的定义才能拥有它们的集合,您不能只向前声明它们。编译器需要知道要为它们使用多少内存。