prototype for “….” does not match any in class “…”

Your header file with class student_Example doesn’t promise a constructor. (And seems to be missing and #endif)

#ifndef STUDENT_EXAMPLE_H
#define STUDENT_EXAMPLE_H
#include <iostream>
#include <string>

class student_Example
{
    public:
        student_Example(char nam, int marc1, int marc2); //<-- as pointed out in the error
        char name;
        int mark1, mark2;

        int calc_media(){
           return (mark1+mark2/2);
        }

       void disp(){
           std::cout<< " The student named: "<< name<< "\n has an average score equal to: " << calc_media()<<"\n";
        }



};
#endif  //<-- this too

While we are there we can use an member initialiser list in the constructor

student_Example::student_Example(char nam, int marc1, int marc2) :
    name(nam),
    mark1(marc1),
    mark2(marc2) //assume maerc2 was a typo
{    
}


Edit: Note that student_Example(char nam, int marc1, int marc2) is a declaration that you will define a constructor taking a char and two ints., which you have done in your cpp file.

You can make an object like this

student_Example example('n', 1, 2);

Without this non-default constructor, a default constructor taking no parameters would have been automatically generator for you, so you could have made an object like this:

student_Example example;

Now you have defined a constructor that will no longer happen. You either need to add this to your class, or make sure you use the constructor taking parameters.

Leave a Comment