Re: namespace shortcut
LuB wrote:
For better or worse, I am working on a C++ project following the Java
package convention.
For example, I created a Socket class nested in the namespace
com.X.core.networking.tcp.Socket;
I am using templates quite exclusively ... (very few .cpp files) so my
header files become wasted with alot of namespace directives and
indentation.
namespace com {
namespace X {
namespace core {
namespace networking {
namespace tcp {
template<typename T>
class Socket
{
etc.
Is there a way around this in the declaration of the class? I realize
this isn't legal, but something like
namespace com::X::core::networking::tcp {
class Socket
There is no way to avoid opening all of the nested namespaces when
declaring the class template Socket. Once declared however, the Socket
class template can be defined elsewhere.
Furthermore, the program can spare itself the tedium of re-specifying
all of Socket's enclosing namespace with a well-placed namespace alias:
namespace com
{
namespace X
{
namespace core
{
namespace networking
{
namespace tcp
{
// declared - not defined
template <class T>
class Socket;
}}}}}
// declare a handy namespace alias
namespace Net = com::X::core::networking::tcp;
// now define the Socket class template
template <class T>
class Net::Socket
{
public:
Socket();
...
};
Greg
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]