getting error:error: no matching function for call to 'Supervisor::Supervisor()' Supervisor s1;

#include <iostream>
#include<iomanip>
using std::ios;
using std::setiosflags;
using std::setprecision;
using std::ostream;
using std::cout;
using std::endl;


class Time
{
public:
Time(int =0,int =0,int =0);
void setTime(int,int,int);
void setHour(int);
void setMinute(int);
void setSeconds(int);
int getHour() const;
int getMinute() const;
int getSeconds() const;
void printMilitary() const;
void printStandard();
private:
int hour,minute,seconds;

};
Time::Time( int h,int m,int s)
{
setTime(h,m,s);

}
void Time::setHour(int h)
{
hour=h;
}
void Time::setMinute(int m)
{
minute=m;
}
void Time::setSeconds(int s)
{
seconds=s;
}
void Time:: setTime(int h,int m,int s)
{
cout<<(hour<24?"0":" ")<<":"<<(minute<59?"0":" ")<<":"<<(seconds<59?"0":" ");

}
int Time::getHour() const
{
return hour;

}
int Time::getMinute() const
{
return minute;

}
int Time::getSeconds() const
{
return seconds;
}

class Date: public Time
{
public:
Date( int = 0, int = 0, int = 0);
void print() const ;
~Date();
int setdate(int,int,int);
private:
int month;
int day;
int year;
int checkDay( int);
};
Date::Date(int dt,int mn,int yr)
{
setdate(dt,mn,yr);

}
int Date::checkDay(int dt)
{
cout<<(dt<31?"0":"");
}
int Date::setdate( int dt,int mn,int yr)
{
day=dt;
month=mn;
year=yr;
cout<<day<<"-"<<month<<"-"<<year;
}
class Project:public Time
{
public:
~Project();
Project(char);
void setProject(char );

};
Project::Project(char pname)
{
setProject(pname);
}
void Project::setProject(char nm)
{
cout<<"Project Name-"<<nm;
}
class Supervisor
{
public:
~Supervisor();
Supervisor(char);
void setnm(char n)
{
cout<<"Supervisor Name-"<<n;
}

};
Supervisor::Supervisor(char n)
{
setnm(n);
}
class Student:public Date
{
public:
~Student();
double setStudent(int,char);
Student(int,char);
protected:
int ID;
char sname;
};
Student::Student(int id,char nme)

{
setStudent(id,nme);
}
double Student::setStudent( int id,char nme)
{
cout<<"Student Name-"<<nme<<endl;
cout<<"ID-"<<id;
}
int main()
{
Time t;
t.setTime(10,20,2);
Date d;
d.setdate(20,03,2018);
Supervisor s1;
s1.setnm('jack');
Student st;
st.setStudent(213,'joe');
}
Supervisor s1;
This is an attempt to use the default constructor. The constructor function that looks like this:
Supervisor::Supervisor()

There is no such function defined. You can't use functions that don't exist.
so how should it can be rectified?
Write that function in your Supervisor class, or don't try to call it.
s1.setnm('jack');

This line makes no sense also. The ' ' should go around a single (ONE) character, but you're using illegal syntax to try to put it around four characters.

That function takes a single char. ONE char. But you're trying to make it take FOUR char. See the problem?
okay thanks
First of all, please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

Your code:
1
2
3
4
5
6
7
8
9
10
11
12
class Supervisor
{
public:
  ~Supervisor();
  Supervisor(char);
  void setnm(char);
};

int main()
{
  Supervisor s1; // error: no constructor that takes 0 arguments.
}

Your class has three members:
1. Destructor
2. Constructor that takes 1 char argument
3. setnm() function that takes 1 char argument

A constructor that takes no arguments is called default constructor.
If a class has no constructors, then compiler generates default constructor.


You could:

1. Use the existing constructor:
1
2
3
4
int main()
{
  Supervisor s1('x'); // calls Supervisor::Supervisor(char)
}


2. Force compiler to create the default constructor
1
2
3
4
5
6
7
8
class Supervisor
{
public:
  ~Supervisor();
  Supervisor() = default;
  Supervisor(char);
  void setnm(char);
};


3. Explicitly define the default constructor:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Supervisor
{
public:
  ~Supervisor();
  Supervisor();
  Supervisor(char);
  void setnm(char);
};

Supervisor::Supervisor()
// member initializer list
{
  // code
}



PS 'jack' and 'joe' are not proper char. Single quotes hold one char.
"jack" and "joe" are not char either. They are constant C-string literals.
Last edited on
bt by double " " they are showing error
bt by double " " they are showing error


"jack" will work for a function that expects a char-pointer. But all this is a waste of time. Just use string

Last edited on
Just use string.
Topic archived. No new replies allowed.