| | |
Composition problem "'XXX' is not a base or member"
Thread Solved
![]() |
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:
What am I missing? Here's the code:
PERSON HAS DATE AND CARD
PERSON IMPLEMENTATION
// DATE CLASS
//CARD CLASS
// MAIN FUNCTION
•
•
•
•
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
PERSON HAS DATE AND CARD
C++ Syntax (Toggle Plain Text)
#ifndef PERSON_H #define PERSON_H #include <iostream> #include <string> #include "date.h" #include "card.h" using std::string; using std::cout; using std::endl; class PERSON { protected: CARD DETAILS; DATE DOB; DATE DOR; private: string FirstName; string LastName; string MI; string Gender; public: PERSON(); PERSON(CARD &, string, string, string, string, DATE &, DATE &); PERSON(const PERSON &); ~PERSON(); void setID(int); void setFname(string ); void setLname(string ); void setMi(string); void setGender(string ); inline string getFname() const; inline string getLname() const; inline string getMi() const; string getGender() const; virtual void Show() const; }; #endif
PERSON IMPLEMENTATION
C++ Syntax (Toggle Plain Text)
#include "person.h" #include "date.h" PERSON::PERSON() : CARD(123456, "Staff"), DATE(01,01,2000), DATE(01,01,2008) { FirstName = "John"; LastName = "Doe"; MI = "D"; Gender = "Male"; } PERSON::PERSON(CARD &DETAILS, string fName, string lName, string mi, string sex, DATE &DOB, DATE &DOR) : CARD(DETAILS), DATE(DOB), DATE(DOR) { FirstName = fName; LastName = lName; MI = mi; Gender = sex; } PERSON::PERSON(const PERSON &cpy) : CARD(DETAILS), DATE(DOB), DATE(DOR) { setFname(cpy.getFname()); setLname(cpy.getLname()); setMi(cpy.getMi()); setGender(cpy.getGender()); } /*PERSON::PERSON(const PERSON &obj) { sID=obj.sID; DOB = obj.DOB; DOR = obj.DOR; FirstName=obj.FirstName; LastName=obj.LastName; //MI=obj.MI; Department = obj.Department; Gender=obj.Gender; count++; }*/ PERSON::~PERSON() { } void PERSON::setFname(string fname) { FirstName=fname; } void PERSON::setLname(string lname) { LastName=lname; } void PERSON::setMi(string mi) { MI=mi; } void PERSON::setGender(string gen) { Gender=gen; } inline string PERSON::getFname() const{return FirstName;} inline string PERSON::getLname() const{return LastName;} inline string PERSON::getMi() const{return MI;} inline string PERSON::getGender() const{return Gender;} void PERSON::Show() const { DETAILS.Show(); cout<<endl <<"Name: " <<FirstName <<" " <<MI <<". " <<LastName <<endl <<"Gender: " <<Gender <<endl <<"Date of Birth: "; DOB.Show(); cout<<endl <<"Date of Reg.: "; DOR.Show(); cout<<endl; }
// DATE CLASS
C++ Syntax (Toggle Plain Text)
#ifndef DATE_H #define DATE_H #include <iostream> using std::cout; class DATE { private: int Day; int Month; int Year; public: //DATE();//Default constructor DATE(int d=1, int m=1, int y=2008) //constructor { Day=d; Month=m; Year=y; } //~ DATE(); void setDay (int d) { Day = d; } void setMonth(int m) { Month=m; } void setYear(int y) { Year = y; } int getDay() const { return Day; } int getMonth() const { return Month; } int getYear() const { return Year; } void Show() const { cout<<Day <<"/" <<Month <<"/" <<Year; } }; #endif
//CARD CLASS
C++ Syntax (Toggle Plain Text)
#ifndef CARD_H #define CARD_H #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class CARD { private: int IDNo; string Type; public: CARD(int id=0, string type="")//constructor with default arguments { IDNo=id; Type=type; } //CARD(const CARD &);//copy constructor //~CARD(); //Mutators void setIdNo(int id) { IDNo = id; } void setType(string type) { Type=type; } //Accessors int getIdNo() const { return IDNo; } string getType() const { return Type; } void Show() const { cout<<"ID #: " <<IDNo <<endl <<"Type: " <<Type; } bool AuthorizeEntry(char parkingLot) { bool authorized; if(Type=="Student" && (parkingLot=='C' || parkingLot=='D' || parkingLot=='E')) authorized=true; else authorized=false; return authorized; } }; #endif
// MAIN FUNCTION
C++ Syntax (Toggle Plain Text)
#include "person.h" #include "student.h" #include "staff.h" #include "card.h" #include <iostream> using std::cout; using std::endl; int main() { return 0; }
![]() |
Other Threads in the C++ Forum
- Previous Thread: EOF problem
- Next Thread: Use of structure and pointer problem
| Thread Tools | Search this Thread |
api application array based binary bitmap c# c++ c/c++ char class classes code coding compile compression console conversion count cpm delete deploy deque desktop developer dialog directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer introductory java lib linkedlist linkednodes linker loop looping loops map math matrix memory multiple news node numbertoword output parameter pointer problem program programming project python random read recursion reference rpg security sorting string strings temperature template test text text-file tree url variable vector video whyisthiscodecausingsegmentationfault win32 windows winsock wordfrequency wxwidgets





