Автор: .exp (18.03.2010 в 17:36)
не замечал такое.
Фактически должны быть записи using namespace std; для того чтобы не делать
std::cout << std::endl; вместо cout << endl;
А так возможно уже в подключаемых файлах где-то объявлено это using
Try It Out - The using Declaration
The function declarations go in the header file compare.h as we discussed above:
// compare.h
namespace compare
{
double max(const double* data, int size);
double min(const double* data, int size);
} |
We will put the definitions for the functions in a separate .cpp file that will contain the following code:
// compare.cpp
#include "compare.h"
// Function to find the maximum
double compare::max(const double* data, int size)
{
double result = data[0];
for(int i = 1 ; i < size ; i++)
if(result < data[i])
result = data[i];
return result;
}
// Function to find the minimum
double compare::min(const double* data, int size)
{
double result = data[0];
for(int i = 1 ; i < size ; i++)
if(result > data[i])
result = data[i];
return result;
} |
All we need is a .cpp file containing the definition of main() to try the functions out:
// Ex5_09.cpp
// Using functions in a namespace
#include <iostream>
#include "compare.h"
using compare::max; // Using declaration for max
using compare::min; // Using declaration for min
int main()
{
double data[] = {1.5, 4.6, 3.1, 1.1, 3.8, 2.1};
using namespace std; // Using directive for standard library
const int dataSize = sizeof data/sizeof data[0];
cout << endl;
cout << "Minimum double is " << min(data, dataSize) << endl;
cout << "Maximum double is " << max(data, dataSize) << endl;
return 0;
} |
(Wrox Press C++ tutorial)