NameSpace
#include<iostream>
using namespace std;
namespace my
{
int b,x=21;
void display();
int fun2();
class stu
{
private:
char a[10];
public:
void Name();
// int age(int); //Declare
int age(int p) //Define
{
cout<<"X in age function :"<<x<<endl;
x=p;
cout<<x<<endl;
p=x+2;
cout<<p<<endl;
return p;
}
};
}
void my::stu::Name()
{
cout<<"Enter Your Name:";
gets(a);
puts(a);
cout<<endl;
}
void my::display()
{
cout<<"Namespace fun"<<endl;
}
using namespace my;
int main()
{
// int x=21; we can't access any veriable of main body scope in other scope
stu student;
b=3;
int s;
int &p=x;
cout<<b<<endl;
display();
student.Name();
s=student.age(15);
cout<<s<<endl;
fun2();
return 0;
}
namespace my
{
// int fun2(); this is not allowed
int fun2()
{
cout<<"Welcome in Fun 2"<<endl<<x;
}
}
using namespace std;
namespace my
{
int b,x=21;
void display();
int fun2();
class stu
{
private:
char a[10];
public:
void Name();
// int age(int); //Declare
int age(int p) //Define
{
cout<<"X in age function :"<<x<<endl;
x=p;
cout<<x<<endl;
p=x+2;
cout<<p<<endl;
return p;
}
};
}
void my::stu::Name()
{
cout<<"Enter Your Name:";
gets(a);
puts(a);
cout<<endl;
}
void my::display()
{
cout<<"Namespace fun"<<endl;
}
using namespace my;
int main()
{
// int x=21; we can't access any veriable of main body scope in other scope
stu student;
b=3;
int s;
int &p=x;
cout<<b<<endl;
display();
student.Name();
s=student.age(15);
cout<<s<<endl;
fun2();
return 0;
}
namespace my
{
// int fun2(); this is not allowed
int fun2()
{
cout<<"Welcome in Fun 2"<<endl<<x;
}
}
Post a Comment