matching function and argument error – but output is good

  arguments, c++, function, oop

Good day everyone,

WARNING!!! I have a bit of classwork that I have been working on for a few days now. I have chopped down the code to prevent plagiarism. I am not too worried though because this is a basic assignment that I have worked out in other classes using Java, Objective C and Python before. I am just new to C++ and transferring sucks.

I need to write definitions in both the setDate method/member and the constructor then implement a leap year check. This needs to be done in Mindtap (education webpage assignment stuff – not VS or anything else cool)

I learned a valuable lesson last week about Mindtap and ran the program before writing any code to see what was being checked.
The way I read the test(s) is:

TEST(Date, 3) {
dateType date3(2, 30, 2009);      //I think this is the input that is being tested
// output
std::string output = testing::internal::GetCapturedStdout();
    ASSERT_TRUE(output == "2-1-2009");     //I think this is the "dateType" output expected which is why I try to convert int into str at one point
    ASSERT_FALSE(date3.isLeapYear());     // I think this says it wants to see isLeapYear return false

There are two more test’s but I don’t want to be redundant here and they only check different dates. I have written the validation so the month and day will set to 1 if they are not within the expected scope because of what it seems to need to see.
When I run the program, the output is as expected (see attached screen shot)

However when I run the checks/test (which is not the program terminal but Mindtap) I get the following Build Output with the same error message from above:

In file included from /usr/include/gtest/gtest.h:58:0,
                 from /root/sandbox54af2570/nt-test-ccd08802.cpp:1:
/root/sandbox54af2570/nt-test-ccd08802.cpp: In member function 'virtual void 
/root/sandbox54af2570/nt-test-ccd08802.cpp:11:35: error: no matching function for call to 

// I dont know how I dont have a matching function.... this is where I have spent a good chunk of my time. If I missed a simple spelling error I might need to order a pizza and beer for the night

In file included from /root/sandbox54af2570/nt-test-ccd08802.cpp:3:0:
/root/sandbox54af2570/dateTypeImp.cpp:75:8: note: candidate: bool dateType::isLeapYear(int)
   bool dateType::isLeapYear(int year)
/root/sandbox54af2570/dateTypeImp.cpp:75:8: note:   candidate expects 1 argument, 0 provided 

// If I understand this correctly, I am not passing an argument. Do I not pass y which it used. if not how is the output as expected? 

make[2]: *** [CMakeFiles/runTests.dir/nt-test-ccd08802.cpp.o] Error 1
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
make: *** [all] Error 2

I have tried:

  • turning the date into a string to be checked

  • outputting the 1/0 from the bool

  • outputting true/false from the bool

  • building everything in the class file

  • building just the bool in the class file

  • changing bool into void and just using an if statement to return the cout

  • outputting the date one part at a time m d y

  • adding the bool to the printDate (errors about mixing types)

  • making the user input m then day then year

  • I even rebuilt the entire thing to only check and adjusted the specific dates from the test

  • scoured SO for "no matching function" – normally was a spelling error

  • scoured SO for "candidate expects 1 argument, 0 " normally a simple mistake of not passing the variable when the function is called.

  • and a lot more things searched in SO and ideas attempted, from the "oh this might be it" to the "its silly but Ill try anyway".

I am not sure what I am not seeing or misinterpreting – I would like to blame the system, but I doubt that is the issue.

I don’t need an answer, I only need to be pointed in the right direction because I have exhausted most of the "try and fail" tactics I can think of.

Any constructive feedback is greatly appreciated. Any advice is always welcome as well. Thank you all for your time.

Note: before we go passing judgement – YES I asked the teacher and the reply I got was "maybe you should look into a tutor for these things" which is not much help. Online classes are not the best for instruction.

//class file - everything here was provided in class
#ifndef date_H 
#define date_H

class dateType
void setDate(int month, int day, int year);

int getDay() const;

int getMonth() const;

int getYear() const;

void printDate() const;

bool isLeapYear(int year);

dateType(int month=0, int day=0, int year=0);

int dMonth;      //variable to store the month
int dDay;        //variable to store the day
int dYear;       //variable to store the year


Here is the implementation file:

#include <iostream>
#include <stdbool.h>
#include "dateType.h"

using namespace std;

void dateType::setDate(int month, int day, int year)
 //validation here as per the instructions code omitted but it returns the desired int's. It is a pretty standard make sure the month is not greater than 12 and use a switch for all 12 cases to be used to validate the day given in the date
 // getters are all implimented 
  int dateType::getDay() const

  int dateType::getMonth() const

  int dateType::getYear() const

  void dateType::printDate() const //I need to leave this in just in case this is where I am messing up
  string m = to_string(dMonth);  // Here I tried to convert my int to str to see if that is what was needed. still fails
  string d = to_string(dDay);
  string y = to_string(dYear);
  //cout << dMonth << "-" << dDay << "-" << dYear<<endl; //first successful attempt that failed – used with another note in main

  bool dateType::isLeapYear(int year) 
// the standard leap year check using an if statement 

dateType::dateType(int month, int day, int year)
  the exact same thing I have in the setDate method/definition - instructions want the validation here as well

Finally here is the main file:

#include <iostream>
#include <stdbool.h>
#include "dateType.h"
using namespace std;

int main() {

int m1 = 3;
int d1 = 15;
int y1 = 2008;

dateType date1(m1,d1,y1);

int m2 = 15;
int d2 = 20;
int y2 = 2008;

dateType date2(m2,d2,y2);

int m3 = 2;
int d3 = 30;
int y3 = 2009;

dateType date3(m3,d3,y3);

cout<<"is a leap year"<<endl;
cout<<"is not a leap year"<<endl;

cout<<"is a leap year"<<endl;
cout<<"is not a leap year"<<endl;

cout<<"is a leap year"<<endl;
cout<<"is not a leap year"<<endl;

 //  ***Here is what worked but failed the tests at first in the main. I used this with the 
alternate printDate definition

 //dateType date1(3,15,2008);
//dateType date2(15,20,2008);
//dateType date3(2,30,2009);

//cout << "this " << (date1.isLeapYear() ? "is" : "is not")
//<< " a leap year.n";

return 0;

Here is my output:
enter image description here

Source: Windows Questions C++