namespace
#include <iostream>
using namespace std;
namespace {
int x;
void display();
}
namespace{
void display(){
cout << "x is "<<x<<endl;
}
}
int main()
{
x = 25;
display();
return 0;
}
namespace
#include <iostream>
using namespace std;
namespace {
int x;
void display();
}
namespace{
void display(){
cout << "x is "<<x<<endl;
}
}
int main()
{
x = 25;
display();
return 0;
}
namespace
// namespaces
#include <iostream>
using namespace std;
namespace foo
{
int value() { return 5; }
}
namespace bar
{
const double pi = 3.1416;
double value() { return 2*pi; }
}
int main () {
cout << foo::value() << '\n';
cout << bar::value() << '\n';
cout << bar::pi << '\n';
return 0;
}
access the namespace members using namespace member function
namespace Parent
{
inline namespace new_ns
{
template <typename T>
struct C
{
T member;
};
}
template<>
class C<int> {};
}
access the namespace members using namespace member function
//Header.h
#include <string>
namespace Test
{
namespace old_ns
{
std::string Func() { return std::string("Hello from old"); }
}
inline namespace new_ns
{
std::string Func() { return std::string("Hello from new"); }
}
}
#include "header.h"
#include <string>
#include <iostream>
int main()
{
using namespace Test;
using namespace std;
string s = Func();
std::cout << s << std::endl; // "Hello from new"
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us