I am using Code Blocks v16*
I got this error and I cannot figure out what seemed to be the problem:
Person.cpp:17:62: note: mismatched types ‘const std::basic_string<_CharT, _Traits, _Alloc>’ and ‘void’ std::cout << "Birthdate: " << BirthdateObj.showBirthDate(); ^ Process terminated with status 1 (0 minute(s), 0 second(s)) 1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Here is my simple program:
Person.h
#ifndef PERSON_H
#define PERSON_H
#include <Birthdate.h>
class Person
{
public:
Person(int age, Birthdate BirthdateObj);
virtual ~Person();
void showPersonInformation();
private:
int age;
Birthdate BirthdateObj;
};
#endif // PERSON_H
Person.cpp
#include "Person.h"
#include <iostream>
Person::Person(int age, Birthdate BirthdateObj) : age(age), BirthdateObj(BirthdateObj)
{
//ctor
}
Person::~Person()
{
//dtor
}
void Person::showPersonInformation()
{
std::cout << "Current age: " << age << std::endl;
std::cout << "Birthdate: " << BirthdateObj.showBirthDate();
}
Birthdate.h
#ifndef BIRTHDATE_H
#define BIRTHDATE_H
class Birthdate
{
public:
Birthdate(int day, int month, int year);
virtual ~Birthdate();
void showBirthDate();
private:
int day, month, year;
};
#endif // BIRTHDATE_H
Birthdate.cpp
#include "Birthdate.h"
#include <iostream>
Birthdate::Birthdate(int day, int month, int year) : day(day), month(month), year(year)
{
//ctor
}
Birthdate::~Birthdate()
{
//dtor
}
void Birthdate::showBirthDate()
{
std::cout << day << "/" << month << "/" << year;
}
main.cpp
#include <iostream>
#include "Birthdate.h"
#include "Person.h"
int main()
{
Birthdate BirthdateObj(7, 16, 1995);
//Birthdate *pBirthdateObj = &BirthdateObj;
Person PersonObj(20, BirthdateObj);
Person *pPersonObj = &PersonObj;
pPersonObj->showPersonInformation();
//pBirthdateObj->showBirthDate();
return 0;
}