C++ namespace to include function

Description

C++ namespace to include function

#include <string>
#include <iostream>

using std::string;

int print_count = 0;

namespace print1 {
  // Function prototype
  void print(const string& s);
}

namespace print2 {
  // Function prototype
  void print(const string& s);
}

void print1::print(const string& s) {
  std::cout << s << " (Namespace name is print1.) " << std::endl;
}

void print2::print(const string& s) {
  std::cout << s << " (Namespace name is print2.) " << std::endl;
}


void print_that(const string& s)
{
  print2::print(s);/*from  w w w. ja v a 2 s.  c  o m*/
}

void print_this(const string& s)
{
  print1::print(s);
}


int main(){
  print_this("This");
  print_that("That");

  std::cout << "The print() function has been called a total of "      // ADDED
            << print_count << " times. " << std::endl;                 // ADDED
}



PreviousNext

Related