a problem relate to namespace and using

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Li Daobing

    #1

    a problem relate to namespace and using

    Hello, I want to know whether the following program is legal. the
    g++-4.1 can not compile it

    $ g++ -c bug2.cpp
    bug2.cpp:8: error: expected unqualified-id before '}' token
    bug2.cpp:15: error: 'A' is already declared in this scope
    bug2.cpp:20: error: prototype for 'void n1::B::foo(cons t
    n1::n2::A&)' does not match any in class 'n1::B'
    bug2.cpp:6: error: candidate is: void n1::B::foo(cons t n1::A&)
    $

    // begin bug2.cpp
    // #include "b.hpp"
    namespace n1 {
    class A;
    class B {
    void foo(const A&);
    }
    }

    // #include "a.hpp"
    namespace n1 {
    namespace n2 {
    class A {};
    }
    using n2::A;
    }

    // b.cpp
    namespace n1 {
    void B::foo(const A&) {
    return;
    }
    }
    // end

  • Tom Widmer

    #2
    Re: a problem relate to namespace and using

    Li Daobing wrote:[color=blue]
    > Hello, I want to know whether the following program is legal. the
    > g++-4.1 can not compile it
    >
    > $ g++ -c bug2.cpp
    > bug2.cpp:8: error: expected unqualified-id before '}' token
    > bug2.cpp:15: error: 'A' is already declared in this scope
    > bug2.cpp:20: error: prototype for 'void n1::B::foo(cons t
    > n1::n2::A&)' does not match any in class 'n1::B'
    > bug2.cpp:6: error: candidate is: void n1::B::foo(cons t n1::A&)
    > $
    >
    > // begin bug2.cpp
    > // #include "b.hpp"
    > namespace n1 {
    > class A;[/color]

    declaration of n1::A.
    [color=blue]
    > class B {
    > void foo(const A&);
    > }
    > }
    >
    > // #include "a.hpp"
    > namespace n1 {
    > namespace n2 {
    > class A {};
    > }
    > using n2::A;[/color]

    using declaration of n1::A. This clashes with the n1::A declaration
    above, since the two declarations refer to different classes (n1::A and
    n1::n2::A).

    Tom

    Comment

    Working...