C++ namespace Nesting

Introduction

You can define one namespace inside another.

namespace outer//from w  w w .  j a va  2s.  c  o m
{
  double max(const std::vector<double>& data)
  {
    // body code..
  }

  double min(const std::vector<double>& data)
  {
   // body code..
  }

  namespace inner
  {
    void normalize(std::vector<double>& data)
    {
       // ...
       double minValue {min(data, size)};   // Calls max() in outer namespace
       // ...
    }
  }
}

void outer::inner::normalize(std::vector<double>& data)
{
  // ...
  double minValue{min(data)};          // Calls min() in outer
  // ...
}



PreviousNext

Related