a problem relate to namespace and using

Discussion in 'C++' started by Li Daobing, Jun 21, 2006.

  1. Li Daobing

    Li Daobing Guest

    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(const
    n1::n2::A&)' does not match any in class 'n1::B'
    bug2.cpp:6: error: candidate is: void n1::B::foo(const 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
    Li Daobing, Jun 21, 2006
    #1
    1. Advertising

  2. Li Daobing

    Tom Widmer Guest

    Li Daobing wrote:
    > 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(const
    > n1::n2::A&)' does not match any in class 'n1::B'
    > bug2.cpp:6: error: candidate is: void n1::B::foo(const n1::A&)
    > $
    >
    > // begin bug2.cpp
    > // #include "b.hpp"
    > namespace n1 {
    > class A;


    declaration of n1::A.

    > class B {
    > void foo(const A&);
    > }
    > }
    >
    > // #include "a.hpp"
    > namespace n1 {
    > namespace n2 {
    > class A {};
    > }
    > using n2::A;


    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
    Tom Widmer, Jun 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keithb
    Replies:
    1
    Views:
    2,713
    Teemu Keiski
    Apr 8, 2006
  2. Jerry
    Replies:
    10
    Views:
    498
  3. Ben Daniel
    Replies:
    4
    Views:
    2,748
    Ben Daniel
    Oct 14, 2007
  4. markla
    Replies:
    1
    Views:
    531
    Steven Cheng
    Oct 6, 2008
  5. Navin
    Replies:
    1
    Views:
    671
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page