namespace is not visible in a class?

Discussion in 'C++' started by r.z., Mar 28, 2007.

  1. r.z.

    r.z. Guest

    I include 2 headers: the first defines some namespace A and the second
    defines class B which contains some member instances of classes defined in
    namespace A.

    header1:

    namespace A
    {
    class C;
    };

    header2:

    class B
    {
    A::C c_instance;
    };

    Why does the compiler complain during compilation of header2 that A is not a
    namespace?
    r.z., Mar 28, 2007
    #1
    1. Advertising

  2. r.z.

    Colander Guest

    On Mar 29, 12:01 am, "r.z." <> wrote:
    > I include 2 headers: the first defines some namespace A and the second
    > defines class B which contains some member instances of classes defined in
    > namespace A.
    >
    > header1:
    >
    > namespace A
    > {
    > class C;
    >
    > };
    >
    > header2:
    >
    > class B
    > {
    > A::C c_instance;
    >
    > };
    >
    > Why does the compiler complain during compilation of header2 that A is not a
    > namespace?


    My compiler says "field 'c_instance' has incomplete type" when tried.

    Could you post some minimal code that shows the error?
    Colander, Mar 28, 2007
    #2
    1. Advertising

  3. r.z.

    r.z. Guest


    > My compiler says "field 'c_instance' has incomplete type" when tried.
    >
    > Could you post some minimal code that shows the error?
    >


    just put class C definition instead of its declaration in namespace A and it
    shoul give you the same error as me
    r.z., Mar 28, 2007
    #3
  4. r.z.

    Ian Collins Guest

    r.z. wrote:
    > I include 2 headers: the first defines some namespace A and the second
    > defines class B which contains some member instances of classes defined in
    > namespace A.
    >
    > header1:
    >
    > namespace A
    > {
    > class C;
    > };
    >
    > header2:
    >
    > class B
    > {
    > A::C c_instance;
    > };
    >
    > Why does the compiler complain during compilation of header2 that A is not a
    > namespace?
    >

    Because you haven't included header1?

    --
    Ian Collins.
    Ian Collins, Mar 28, 2007
    #4
  5. r.z.

    r.z. Guest

    > Because you haven't included header1?

    it is included - I can use A::C c_instance in main.cpp but not in header2.
    r.z., Mar 28, 2007
    #5
  6. r.z.

    Colander Guest

    On Mar 29, 12:25 am, "r.z." <> wrote:
    > > My compiler says "field 'c_instance' has incomplete type" when tried.

    >
    > > Could you post some minimal code that shows the error?

    >
    > just put class C definition instead of its declaration in namespace A and it
    > shoul give you the same error as me


    Nope, the next compiles fine;


    namespace A
    {
    class C{
    public:
    C(){};
    };
    };

    class B
    {
    A::C c;
    };

    int main(void)
    {
    B b;
    return 0;
    }


    So, or your compiler is wrong, or there is something else that is
    important to the problem in your code that you havn't posted to this
    group yet....
    Colander, Mar 28, 2007
    #6
  7. r.z.

    r.z. Guest

    SOLVED.
    I did forget to include header1 in header2.
    I am an ass of a developer.
    thanks for comments.
    r.z., Mar 29, 2007
    #7
    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. tshad

    button visible/not visible

    tshad, Oct 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,444
    Brian Hoops
    Oct 28, 2004
  2. tshad

    Sections visible and not visible

    tshad, Jan 31, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,060
    tshad
    Jan 31, 2005
  3. Patrick Olurotimi Ige
    Replies:
    7
    Views:
    5,965
    Patrick Olurotimi Ige
    Jun 15, 2005
  4. tshad
    Replies:
    1
    Views:
    4,246
    tshad
    Oct 31, 2009
  5. Jurjen de Groot
    Replies:
    0
    Views:
    302
    Jurjen de Groot
    May 19, 2008
Loading...

Share This Page