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

Help with instance of one class in another

 
0
  #1
Nov 21st, 2008
Hello everyone.

I need help using an instance of a class in another. Below are two header files. NumDays.h and TimeOff.h

I need to have instances of the NumDays class in the TimeOff class as members. When i try to create the instance called maxSickDays, i do not get access to the NumDays member functions. What is wrong with my code? Thanks in advance.

NumDays.h
  1. #ifndef NUMDAYS
  2. #define NUMDAYS
  3. #include <iostream>
  4.  
  5. class NumDays
  6. {
  7.  
  8. private:
  9. int hours;
  10. float days;
  11. float calcDays();
  12.  
  13. public:
  14. NumDays()
  15. { hours = 0; days = 0.0; }
  16.  
  17. void setHours(int hrs)
  18. { hours = hrs; }
  19. int getHours()
  20. { return hours; }
  21. float getDays();
  22.  
  23. NumDays operator + ( const NumDays& );
  24. NumDays operator - ( const NumDays& );
  25. NumDays operator --();
  26. NumDays operator ++();
  27. NumDays operator ++ ( int );
  28. NumDays operator -- ( int );
  29.  
  30. };
  31.  
  32. #endif

and now 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. public:
  16. TimeOff();
  17.  
  18.  
  19. void setName ( string n )
  20. { name = n; }
  21. void setIdNum ( int id )
  22. { idNum = id; }
  23.  
  24. string getName()
  25. { return name; }
  26. int getIdNum()
  27. { return idNum; }
  28.  
  29. };
  30.  
  31. #endif

Thank you!
Reply With Quote