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:
- make
weather
public. - make
calc
friend ofinputs
. - create getter method
weather
(recommended, since improves encapsulation)
Comments
Post a Comment