friend+namespace

Discussion in 'C++' started by Filimon Roukoutakis, Mar 20, 2007.

  1. Dear all,
    I have the following concept

    name {

    space1 {

    class Friend {

    };

    };

    };

    name {

    space2 {

    MyClass {

    friend name::space1::Friend;

    };

    };

    };

    For some reason I get Error: class, struct, union or type name::space1
    not defined (in the line with the friend declaration). I think I am
    missing something simple. Any ideas? Should I #include the Friend.h file
    in any case? I would like to avoid this. Thanks,

    filimon
    Filimon Roukoutakis, Mar 20, 2007
    #1
    1. Advertising

  2. On 20 Mar, 13:13, Filimon Roukoutakis <> wrote:
    > Dear all,
    > I have the following concept
    >
    > name {
    >
    > space1 {
    >
    > class Friend {
    >
    > };
    > };
    > };
    >
    > name {
    >
    > space2 {
    >
    > MyClass {
    >
    > friend name::space1::Friend;
    >
    > };
    > };
    > };
    >
    > For some reason I get Error: class, struct, union or type name::space1
    > not defined (in the line with the friend declaration). I think I am
    > missing something simple. Any ideas? Should I #include the Friend.h file
    > in any case? I would like to avoid this. Thanks,


    Except for the fact that the above code does not declare any
    namespaces (missing the namespace keyword) I think you have to add ::
    in front of name::space1::Friend since you otherwise try to access a
    class in ::name::space2::name::space1 or some such.

    --
    Erik Wikström
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, Mar 20, 2007
    #2
    1. Advertising

  3. Erik Wikström wrote:
    > On 20 Mar, 13:13, Filimon Roukoutakis <> wrote:
    >> Dear all,
    >> I have the following concept
    >>
    >> name {
    >>
    >> space1 {
    >>
    >> class Friend {
    >>
    >> };
    >> };
    >> };
    >>
    >> name {
    >>
    >> space2 {
    >>
    >> MyClass {
    >>
    >> friend name::space1::Friend;
    >>
    >> };
    >> };
    >> };
    >>
    >> For some reason I get Error: class, struct, union or type name::space1
    >> not defined (in the line with the friend declaration). I think I am
    >> missing something simple. Any ideas? Should I #include the Friend.h file
    >> in any case? I would like to avoid this. Thanks,

    >
    > Except for the fact that the above code does not declare any
    > namespaces (missing the namespace keyword) I think you have to add ::
    > in front of name::space1::Friend since you otherwise try to access a
    > class in ::name::space2::name::space1 or some such.
    >
    > --
    > Erik Wikström
    >


    Unfortunately I get the same Error class, struct, union or type
    ::name::space1 not defined.
    Filimon Roukoutakis, Mar 20, 2007
    #3
  4. Filimon Roukoutakis

    BobR Guest

    Filimon Roukoutakis <> wrote in message...
    > Erik Wikström wrote:
    > > On 20 Mar, 13:13, Filimon Roukoutakis <> wrote:
    > >> Dear all,
    > >> I have the following concept
    > >>
    > >> name{
    > >> space1{
    > >> class Friend{};
    > >> };
    > >> };
    > >>
    > >> name{
    > >> space2{
    > >> MyClass{
    > >> friend name::space1::Friend;
    > >> };
    > >> };
    > >> };
    > >>
    > >> For some reason I get Error: class, struct, union or type name::space1
    > >> not defined (in the line with the friend declaration). I think I am
    > >> missing something simple. Any ideas? Should I #include the Friend.h

    file
    > >> in any case? I would like to avoid this. Thanks,

    > >
    > > Except for the fact that the above code does not declare any
    > > namespaces (missing the namespace keyword) I think you have to add ::
    > > in front of name::space1::Friend since you otherwise try to access a
    > > class in ::name::space2::name::space1 or some such.
    > > - - Erik Wikström
    > >

    >
    > Unfortunately I get the same Error class, struct, union or type
    > ::name::space1 not defined.


    namespace name1{
    namespace space1{
    class Friend{};
    }
    }

    namespace name1{ // add to name1
    namespace space2{
    class MyClass{
    // friend class name1::space1::Friend;
    friend class space1::Friend;
    };
    }
    }

    --
    Bob R
    POVrookie
    BobR, Mar 21, 2007
    #4
    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. Alexander Grigoriev
    Replies:
    6
    Views:
    2,548
    Kevin Goodsell
    Sep 12, 2003
  2. Tim Partridge
    Replies:
    2
    Views:
    608
    Nick Hounsome
    Jan 8, 2004
  3. Tim Partridge
    Replies:
    1
    Views:
    706
    Sumit Rajan
    Jun 2, 2004
  4. marco_segurini
    Replies:
    4
    Views:
    1,001
    Rob Williscroft
    Jun 16, 2004
  5. Peter
    Replies:
    2
    Views:
    272
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page