View Single Post
Join Date: Oct 2008
Posts: 29
Reputation: jbrock31 is an unknown quantity at this point 
Solved Threads: 1
jbrock31 jbrock31 is offline Offline
Light Poster

Re: Help with instance of one class in another

 
0
  #4
Nov 21st, 2008
I figured out my problem. When i defined the mutator and accessor functions in the cpp file instead of the header i was able to access the nested class' member variables and functions. Below are my revised header and cpp files.

TimeOff.h
  1. #ifndef TIMEOFF
  2. #define TIMEOFF
  3. #include <iostream>
  4. #include "NumDays.h"
  5. #include <string>
  6. using namespace std;
  7.  
  8. class TimeOff
  9. {
  10. private:
  11. string name;
  12. int idNum;
  13. NumDays maxSickDays;
  14.  
  15.  
  16. public:
  17. TimeOff();
  18.  
  19.  
  20. void setName ( string n )
  21. { name = n; }
  22. void setIdNum ( int id )
  23. { idNum = id; }
  24. void setMaxSickDays( int );
  25.  
  26.  
  27.  
  28. float getMaxSickDays();
  29. string getName()
  30. { return name; }
  31. int getIdNum()
  32. { return idNum; }
  33.  
  34.  
  35.  
  36. };
  37.  
  38. #endif

now TimeOff.cpp
  1. #include "TimeOff.h"
  2. #include "NumDays.h"
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. TimeOff::TimeOff()
  8. {
  9. name = "";
  10. idNum = 0;
  11. maxSickDays.setHours(0);
  12. // sickTaken.setHours(0);
  13. // maxVacation.setHours(0);
  14. // vacTaken.setHours(0);
  15. // maxUnpaid.setHours(0);
  16. // unpaidTaken.setHours(0);
  17. }
  18. void TimeOff::setMaxSickDays ( int hrs )
  19. {
  20. maxSickDays.setHours(hrs);
  21.  
  22. }
  23. float TimeOff::getMaxSickDays()
  24. {
  25. return maxSickDays.getDays();
  26. }
Reply With Quote