| declarations-definitions/decl-def-problems.cc - Illustration of declarations and definitions - several problems. | Lecture 2 - slide 5 : 29 Program 2 |
#include <iostream>
#include <string>
using std::string;
string s; // DEFINES s to be the empty string.
string s = "AP"; // Double definition: ERROR
int f(int i){ // DEFINES f to a particular function from
return i + 1; // int to int
}
int f(int j){ // DEFINES f again - double definition - ERROR
return j - 1;
}
double f(double j){ // DEFINES f on double - overload - OK
return j - 1;
}
int g(int); // DECLARES g. OK
struct Date; // DECLARES struct Date. OK
int f() // DEFINES the parameterless function f - an overload
{
Date d; // Incomplete type. The details of of type Date must be known here. ERROR
f(1); // OK
g(2); // OK
}