c++ - structure expected on left side of . or .* but it is a structure -


i'm getting compile error structure required on left side of . or .* on chest.contents[0], chest structure:

class item { public:     int id;     int dmg; };  class chest { public:     item contents[10]; };  int main()  {     chest chest();      item item = chest.contents[0];      return 0; } 

no isn't, it's function takes 0 parameters.

to default-initialize variable, use

chest chest; 

in c++11, syntax can used value-initialization.

chest chest{}; 

in c++03, needs complicated (because of many compiler bugs) workaround, boost library thankfully has made easy use:

boost::value_initialized<chest> chest; 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -