Date Class - Tirgul
#include <iostream>
#include <stdio.h>
#include "Date.h"
using namespace std;
int main() {
// defining a Data Object
Date HerBirthDay(19,8,1976);
printf("Her birthday is on %d / %d / %d \n",
HerBirthDay.theDay( ) , HerBirthDay.theMonth( ),
HerBirthDay.theYear( ) );
HerBirthDay.advance( );
printf("On %d / %d / %d she'll be very happy\n",
HerBirthDay.theDay( ) , HerBirthDay.theMonth( ),
HerBirthDay.theYear( ) );
// HerBirthDay.day_ ++ ; // illegal: day_ is private
// HerBirthDay.month_=8;// illegal: month_ is private
return 0;
}#include <cstdio>
#ifndef DATE_H
#define DATE_H
class Date{
private:
int day_;
int month_;
int year_;
public:
Date(int,int,int);
int theDay() const;
int theMonth() const;
int theYear() const;
void advance(); // A method to change the date
};
#endif // DATE_HFunction Prototype- הצהרה
Const member function
Implementing our Class
Constuctors
Public & Private
Overloading
Watch out from this!
Overloading our advance funcion
advance funcionDefault args
Const
Pointer to a const
const const
Const and functions
Return values from functions
Last updated