Thursday, 21 September 2017

Creating user defined namespace in C++

/*
 Creating user defined namespace in C++
*/
#include "iostream"

namespace first{

 int num1, num2;
 class Student{
  int marks;
  public:
   Student(int num1){
    marks = num1;
    std::cout<<"marks: "<<marks<<std::endl;
   }
 };
}

using namespace std;
//using namespace first;

int main(){
 first::num1 = 10;
 first::num2 = 20;
 first :: Student ob(first::num1);
// cout<<"\n num: "<<ob.marks;
 return 0;
}

/*
 OUTPUT
[pavan@localhost Unit-1-Classes]$ g++ NameSpaceDemo.cpp
[pavan@localhost Unit-1-Classes]$ ./a.out 
marks: 10
[pavan@localhost Unit-1-Classes]$ 

*/

No comments: