| declarations-definitions/decl-def.cc - Illustration of declarations and definitions - everything is fine. | Lecture 2 - slide 5 : 29 Program 1 |
#include <iostream>
#include <string>
using std::string;
string s; // DEFINES s to be the empty string.
int i = 5; // DEFINES i as an int variable initialized to 5
struct Date{ // DEFINES Date to be a type (struct) with three
int d, m, y; // int fields: d, m, and y
};
int f(int i){ // DEFINES f to a particular function from
return i + 1; // int to int
}
extern string t; // DECLARES that t is a string
extern int j; // DECLARES that j an int
struct DateWithWeekday; // DECLARES that DateWithWeekday is a struct - forward declaration
int g(int i); // DECLARES that g is an int returning function of int
DateWithWeekday
h(Date, int); // DECLARES function h from Date and int to DateWithWeekday
struct DateWithWeekday{ // DEFINES an already forwardly declared type
Date wd;
int weekday;
};
int func() // DEFINES a parameterless function func
{
Date d1 = Date();
DateWithWeekday
dwd1,
dwd2 = h(d1, 3);
f(i);
g(j);
}