因此,可以聲明匿名類或結構,但是如何讓它變得有用?如何使用匿名結構或類?
int main() {
class{
int ClassVal;
};
struct{
short StructVal;
};
StructVal = 5; //StructVal is undefined
ClassVal = 5; //ClassVal is undefined too?
return 0;
}
如果你把它們都放在main函數之外,它們也是不可訪問的。 我問這不僅是因爲它以某種方式野趣:)
編輯: 爲什麼主要功能(在全局範圍)之外的工會必須是靜態的聲明 例如:
static struct {
int x;
};
int main() {
//...
}
如果您能說出您正在使用的語言,這將有所幫助。 –
@skaffman,我正在使用C++,我把C++標籤放在了我的文章的下面。謝謝。 – codekiddy