C++ namespace with Functions inside
#include <vector> #include <iostream> namespace compare { using std::vector; double max(const vector<double>& data); double min(const vector<double>& data); } // Function to find the maximum double compare::max(const std::vector<double>& data) { double result {data[0]}; for(const auto value : data) if(result < value) result = value;/* w w w. j a v a 2 s . c o m*/ return result; } // Function to find the minimum double compare::min(const std::vector<double>& data) { double result {data[0]}; for(const auto value : data) if(result > value) result = value; return result; } using compare::max; // Using declaration for max using compare::min; // Using declaration for min int main() { std::vector<double> data {1.5, 4.6, 3.1, 1.1, 3.8, 2.1}; std::cout << "Minimum value is " << min(data) << std::endl; std::cout << "Maximum double is " << max(data) << std::endl; }