C++ namespace Question

Introduction

Write a program that declares a function inside a namespace and defines the function outside the namespace.

Invoke the function in the main program.

Namespace and function names are arbitrary.




#include <iostream> 

namespace MyNameSpace 
{ 
    void myfunction(); 
} 

void MyNameSpace::myfunction() 
{ 
    std::cout << "Hello World from a function inside a namespace."; 
} 

int main() 
{ 
    MyNameSpace::myfunction(); 
} 



PreviousNext

Related