Say I have a namespace Util, which contains some basic functions. But in that namespace I need the functionality of a library to do my work, however I don't want the header file to know about it so I end up making an anonymous namespace with the functionality that I need but don't want exposed. Is there a better way to do this ?
As an example:
# Util.h
namespace Util{ int Add(); }
# Util.cpp
namespace Util{
namespace {
funkyInt Add_internal(int x, int y);
int convert(funkyInt x);
}
int Add(int x, int y){
return convert(Add_internal(x,y))
}
funkyInt Add_internal(int x, int y){
//DOSomething
}
}
That's perfectly fine.
Whether the anonymous namespace is in your namespace or the global one is taste and ease.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.