I am studying further about C++ and come across a topic which describe method to avoid multiple inclusion of header file, which may cause compilational problem.
But I never seen such problem, I've tried to mimic the situation with the below files in Visual C++ 2008 express, no error prompted and run perfectly.
Can anyone tell me?
Thank you.
//header.h
double Square (double x);
double Cube (double x);
//pi.h
double circle_area(double r);
//header.cpp
double Square (double Value)
{
/* Function code */
double SquareReturn;
SquareReturn = Value * Value;
return SquareReturn;
}
/* Function definition */
double Cube (double Value)
{
/* Function code */
double CubeReturn;
CubeReturn = Value * Value * Value;
return CubeReturn;
}
//pi.cpp
#include "header.h"
double circle_area(double r)
{
double area;
area = 3.14 * Square(r);
return area;
}
//main.cpp
#include "header.h"
#include "pi.h"
#include <iostream>
int main (void)
{
double Number;
double SquaredNumber, CubedNumber , CircleArea;
Number = 5;
/* Call the function */
SquaredNumber = Square (Number);
CubedNumber = Cube (Number);
CircleArea = circle_area(Number);
std::cout << "Square of 5 = " << SquaredNumber << std::endl;
std::cout << "Cube of 5 = " << CubedNumber << std::endl;
std::cout << "Area of a circle of radius 5 = " << CircleArea << std::endl;
return 0;
}