I am learning inheritance in C++ and trying to return value from a function "age". All I get back is 0. I have spent hours to figure out, but no luck. This is my code below. I'll greatly appreciate any help on this!
.h class
#include <stdio.h>
#include <string>
using namespace std;
class Mother
{
public:
Mother();
Mother(double h);
void setH(double h);
double getH();
//--message handler
void print();
void sayName();
double age(double a);
private:
double ag;
};
.cpp
#include <iostream>
#include <string>
#include "Mother.hpp"
#include "Daughter.hpp"
using namespace std;
Mother::Mother(){}
Mother::Mother(double h)
{
ag=h;
}
void setH(double h){}
double getH();
void Mother::print(){
cout<<"I am " <<ag <<endl;
}
void Mother::sayName(){
cout<<"I am Sandy" <<endl;
}
double Mother::age(double a)
{
return a;
}
main
#include <iostream>
#include "Mother.hpp"
#include "Daughter.hpp"
using namespace std;
int main(int argc, const char * argv[]) {
Mother mom;
mom.sayName();
mom.age(40);
mom.print();
//Daughter d;
//d.sayName();
return 0;