Composition problem "'XXX' is not a base or member"

Thread Solved
Reply

Join Date: Feb 2008
Posts: 88
Reputation: knight fyre is an unknown quantity at this point 
Solved Threads: 1
knight fyre's Avatar
knight fyre knight fyre is offline Offline
Junior Poster in Training

Composition problem "'XXX' is not a base or member"

 
0
  #1
Mar 20th, 2008
I'm trying to use composition. I included the header file and made a type of the class that is contained within the owner class but I keep getting errors like this:

c:\documents and settings\cheryl\desktop\parking lot system\person.cpp(7) : error C2614: 'PERSON' : illegal member initialization: 'DATE' is not a base or member
c:\documents and settings\cheryl\desktop\parking lot system\person.cpp(7) : error C2614: 'PERSON' : illegal member initialization: 'DATE' is not a base or member
c:\documents and settings\cheryl\desktop\parking lot system\person.cpp(7) : error C2614: 'PERSON' : illegal member initialization: 'CARD' is not a base or member
What am I missing? Here's the code:

PERSON HAS DATE AND CARD
  1. #ifndef PERSON_H
  2. #define PERSON_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include "date.h"
  7. #include "card.h"
  8.  
  9. using std::string;
  10. using std::cout;
  11. using std::endl;
  12.  
  13. class PERSON
  14. {
  15. protected:
  16. CARD DETAILS;
  17. DATE DOB;
  18. DATE DOR;
  19.  
  20. private:
  21. string FirstName;
  22. string LastName;
  23. string MI;
  24. string Gender;
  25.  
  26. public:
  27. PERSON();
  28. PERSON(CARD &, string, string, string, string, DATE &, DATE &);
  29.  
  30. PERSON(const PERSON &);
  31. ~PERSON();
  32.  
  33.  
  34.  
  35. void setID(int);
  36. void setFname(string );
  37. void setLname(string );
  38. void setMi(string);
  39.  
  40. void setGender(string );
  41.  
  42.  
  43. inline string getFname() const;
  44. inline string getLname() const;
  45. inline string getMi() const;
  46.  
  47.  
  48. string getGender() const;
  49.  
  50. virtual void Show() const;
  51. };
  52. #endif

PERSON IMPLEMENTATION

  1. #include "person.h"
  2. #include "date.h"
  3.  
  4.  
  5. PERSON::PERSON()
  6. : CARD(123456, "Staff"), DATE(01,01,2000), DATE(01,01,2008)
  7. {
  8. FirstName = "John";
  9. LastName = "Doe";
  10. MI = "D";
  11. Gender = "Male";
  12. }
  13.  
  14. PERSON::PERSON(CARD &DETAILS, string fName, string lName, string mi, string sex, DATE &DOB, DATE &DOR)
  15. : CARD(DETAILS), DATE(DOB), DATE(DOR)
  16. {
  17. FirstName = fName;
  18. LastName = lName;
  19. MI = mi;
  20. Gender = sex;
  21. }
  22.  
  23. PERSON::PERSON(const PERSON &cpy)
  24. : CARD(DETAILS), DATE(DOB), DATE(DOR)
  25. {
  26. setFname(cpy.getFname());
  27. setLname(cpy.getLname());
  28. setMi(cpy.getMi());
  29. setGender(cpy.getGender());
  30. }
  31.  
  32.  
  33. /*PERSON::PERSON(const PERSON &obj)
  34. {
  35. sID=obj.sID;
  36. DOB = obj.DOB;
  37. DOR = obj.DOR;
  38. FirstName=obj.FirstName;
  39. LastName=obj.LastName;
  40. //MI=obj.MI;
  41. Department = obj.Department;
  42. Gender=obj.Gender;
  43. count++;
  44. }*/
  45.  
  46. PERSON::~PERSON()
  47. {
  48. }
  49.  
  50.  
  51. void PERSON::setFname(string fname)
  52. {
  53. FirstName=fname;
  54. }
  55.  
  56. void PERSON::setLname(string lname)
  57. {
  58. LastName=lname;
  59. }
  60.  
  61. void PERSON::setMi(string mi)
  62. {
  63. MI=mi;
  64. }
  65.  
  66.  
  67.  
  68. void PERSON::setGender(string gen)
  69. {
  70. Gender=gen;
  71. }
  72.  
  73.  
  74. inline string PERSON::getFname() const{return FirstName;}
  75.  
  76. inline string PERSON::getLname() const{return LastName;}
  77.  
  78. inline string PERSON::getMi() const{return MI;}
  79.  
  80. inline string PERSON::getGender() const{return Gender;}
  81.  
  82.  
  83. void PERSON::Show() const
  84. {
  85. DETAILS.Show();
  86. cout<<endl
  87. <<"Name: " <<FirstName <<" " <<MI <<". " <<LastName <<endl
  88. <<"Gender: " <<Gender <<endl
  89. <<"Date of Birth: ";
  90. DOB.Show();
  91. cout<<endl
  92. <<"Date of Reg.: ";
  93. DOR.Show();
  94. cout<<endl;
  95. }

// DATE CLASS
  1. #ifndef DATE_H
  2. #define DATE_H
  3.  
  4.  
  5. #include <iostream>
  6.  
  7. using std::cout;
  8.  
  9. class DATE
  10. {
  11. private:
  12. int Day;
  13. int Month;
  14. int Year;
  15. public:
  16. //DATE();//Default constructor
  17. DATE(int d=1, int m=1, int y=2008) //constructor
  18. {
  19. Day=d;
  20. Month=m;
  21. Year=y;
  22. }
  23.  
  24. //~ DATE();
  25. void setDay (int d)
  26. {
  27. Day = d;
  28. }
  29.  
  30. void setMonth(int m)
  31. {
  32. Month=m;
  33. }
  34.  
  35. void setYear(int y)
  36. {
  37. Year = y;
  38. }
  39.  
  40. int getDay() const
  41. {
  42. return Day;
  43. }
  44.  
  45. int getMonth() const
  46. {
  47. return Month;
  48. }
  49.  
  50. int getYear() const
  51. {
  52. return Year;
  53. }
  54.  
  55. void Show() const
  56. {
  57. cout<<Day <<"/" <<Month <<"/" <<Year;
  58. }
  59. };
  60. #endif


//CARD CLASS
  1. #ifndef CARD_H
  2. #define CARD_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using std::cout;
  8. using std::endl;
  9. using std::string;
  10.  
  11. class CARD
  12. {
  13. private:
  14. int IDNo;
  15. string Type;
  16. public:
  17. CARD(int id=0, string type="")//constructor with default arguments
  18. {
  19. IDNo=id;
  20. Type=type;
  21. }
  22. //CARD(const CARD &);//copy constructor
  23. //~CARD();
  24. //Mutators
  25. void setIdNo(int id)
  26. {
  27. IDNo = id;
  28. }
  29.  
  30. void setType(string type)
  31. {
  32. Type=type;
  33. }
  34.  
  35. //Accessors
  36. int getIdNo() const
  37. {
  38. return IDNo;
  39. }
  40.  
  41. string getType() const
  42. {
  43. return Type;
  44. }
  45.  
  46. void Show() const
  47. {
  48. cout<<"ID #: " <<IDNo <<endl
  49. <<"Type: " <<Type;
  50. }
  51.  
  52. bool AuthorizeEntry(char parkingLot)
  53. {
  54. bool authorized;
  55. if(Type=="Student" && (parkingLot=='C' || parkingLot=='D' || parkingLot=='E'))
  56. authorized=true;
  57. else
  58. authorized=false;
  59.  
  60. return authorized;
  61. }
  62. };
  63.  
  64. #endif

// MAIN FUNCTION
  1. #include "person.h"
  2. #include "student.h"
  3. #include "staff.h"
  4. #include "card.h"
  5.  
  6. #include <iostream>
  7.  
  8. using std::cout;
  9. using std::endl;
  10.  
  11. int main()
  12. {
  13.  
  14. return 0;
  15. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 88
Reputation: knight fyre is an unknown quantity at this point 
Solved Threads: 1
knight fyre's Avatar
knight fyre knight fyre is offline Offline
Junior Poster in Training

Re: Composition problem "'XXX' is not a base or member"

 
0
  #2
Mar 20th, 2008
Problem solved, no worries.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC