NoIdeaForUsername
NoIdeaForUsername

Reputation: 117

How can I extern namespaces in a namespace?

In my previous question, I asked that how can I extern classes in a class, and we could do:

namespace kc
{
    using ::A;
    using ::B;
}

instead of:

namespace kc
{
    class A
    {
        private:
            int value;
        public:
            A(int value);
            int get_value();
    };
    class B
    {
        private:
            int value;
        public:
            B(int value);
            int get_value();
    };
}

And now, I want to do something like this for namespaces, without defining the entire namespace again. I tried to use the same code, but it doesn't work: error: using-declaration may not name namespace <namespace_name>

Edit

Actually, I'm making a kernel, and that's my code (pio.hpp):

#pragma once

namespace pio
{
    void outb(unsigned short port, unsigned char value);
    void outw(unsigned short port, unsigned short value);
    unsigned char inb(unsigned short port);
    unsigned short inw(unsigned short port);
}

And (k.hpp):

#pragma once

#include <pio.hpp>
#include <cursor.hpp>

namespace k
{
    using ::pio;
    using ::cursor;
}

Upvotes: 0

Views: 128

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 545588

I think what you’re looking for is a namespace alias:

namespace A {
    namespace B {
        struct C {};
    }
}

namespace X {
    namespace Y = ::A::B;
}

This would allow you to write e.g.

X::Y::C foo;

Upvotes: 1

Related Questions