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

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -