constructor problems

This is a discussion on constructor problems within the C++ Programming forums, part of the General Programming Boards category; why do i keep getting this error that says theres not appropriate default constructor for the LabCourse? Code: #include<iostream.h> #include<string.h> ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    45

    constructor problems

    why do i keep getting this error that says theres not appropriate default constructor for the LabCourse?


    Code:
    #include<iostream.h>
    #include<string.h>
    
    
    class CollegeCourse
    {
    	protected:
    		char department[3];
    		int courseNumber;
    		int creditHours;
    		double tuition;
    	public:
    		CollegeCourse(const char dept[],const int course,const int hours,const double tuit);
    		void showCollegeCourse();
    };
    class LabCourse:public CollegeCourse
    {
    	private:
    		double fee;
    	public:
    		LabCourse(const char dept[], const int course, const int hours, const double tuit);
    		void showLabCourse();
    };
    
    CollegeCourse::CollegeCourse(const char dept[],const int course,const int hours,const double tuit)
    {
    	strcpy(department, dept);
    	courseNumber=course;
    	creditHours=hours;
    	tuition=tuit;
    };
    LabCourse::LabCourse(const char dept[], const int course, const int hours, const double tuit)
    {
    	strcpy(department, dept);
    	courseNumber=course;
    	creditHours=hours;
    	tuition=tuit;
    	fee=10.25;
    };
    void CollegeCourse::showCollegeCourse()
    {
    	cout<<department<<courseNumber<<" "<<creditHours<<" credits.  Tuition $"<<tuition<<endl;
    }
    void LabCourse::showLabCourse()
    {
    	cout<<department<<courseNumber<<" "<<creditHours<<" credits.  Tuition $"<<tuition<<endl;
    	cout<<"Plus a lab fee of $"<<fee<<endl;
    }
    
    void main()
    {
    
      CollegeCourse cc("ENG",121,3,333.33);
    
      LabCourse lc("CIS",250,4,444.44);
    
      cc.showCollegeCourse();
    
      lc.showLabCourse();
    
    
     }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    try rewriting it properly and see what happens. Derived constructors only initialise base class members by CALLING THE BASE CLASS CONSTRUCTOR and not directly even if they are protected which is probably unnecessary with proper design.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    45
    i would love to write it the right way, but i dont understand whats wrong with it. the book tells me to write this program and then it doesnt say how to use the constructors in sub classes.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21