c++ - Accessing a pointer to a member class which stores a pointer to another member class -


i have 1 class point data storage member class (inputs):

class calc { public:     calc(inputs *input) : input(input) {}     void performcalc(); private:     inputs *input; }; 

in inputs class store various data inputs:

class inputs { public:     inputs(std::string &directory, logfile &log);     ~inputs();  private:      writelogfile &writetolog;     weatherdata *weather;     evaporationdata *evaporation;  friend class calc;  } 

now, when in performcalc() method, can't access weather class in inputs object member of calc class using pointer notation?

input->weather    //does not work 

nor dot notation work (which didn't think would, since nothing linked passed reference here.)

input.weather    //does not work 

what missing?

edit: sorry! forgot mention calc class friend class inputs class.

you have defined weather private member of inputs, isn't visible calc object. have 3 options:

  1. make weather public.
  2. make calc friend of inputs.
  3. create getter method weather (recommended, since improves encapsulation)

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -