#include <iostream>
#include <string>
namespace
test_space1 {
const
std::string const_prefix =
"(test_space1::string) "
;
class
string {
private
:
std::string str =
""
;
string();
public
:
string(
const
std::string& s)
: str(const_prefix + s)
{
}
std::string get_str()
const
{
return
str;
}
};
};
namespace
test_space2 {
const
std::string const_prefix =
"(test_space2::string) "
;
class
string {
private
:
std::string str =
""
;
const
std::string check_scope =
"test_space2!"
;
string();
public
:
string(
const
std::string& s)
: str(const_prefix + s)
{
}
std::string get_str()
const
{
return
str;
}
std::string getScopestr()
const
{
return
check_scope;
}
};
};
namespace
test_space3 {
const
std::string const_prefix =
"(test_space3::string) from both nmspaces test_space3 & "
;
class
string {
std::string str =
""
;
string();
public
:
string(
const
test_space2::string& s)
: str(const_prefix + s.getScopestr())
{
}
std::string get_str()
const
{
return
str;
}
};
};
std::ostream& operator<<(std::ostream& os,
const
test_space1::string& s1)
{
os << s1.get_str();
return
os;
}
std::ostream& operator<<(std::ostream& os,
const
test_space2::string& s2)
{
os << s2.get_str();
return
os;
}
std::ostream& operator<<(std::ostream& os,
const
test_space3::string& s3)
{
os << s3.get_str();
return
os;
}
int
main()
{
const
std::string str(
"This is a standard string"
);
std::cout << str << std::endl;
const
std::string sample1(
"This is a test_space1 namespace string"
);
const
test_space1::string s2(sample1);
std::cout << s2 << std::endl;
const
std::string sample2(
"This is a test_space2 namespace string"
);
test_space2::string s3(sample2);
std::cout << s3 << std::endl;
test_space3::string s4(s3);
std::cout << s4 << std::endl;
return
0;
}