Topic: Aliases illegal in function definition in Standard C++??!!


Author: wmm@fastdial.net
Date: 1999/10/18
Raw View
In article <user-1110991716340001@as1-dialup-67.io.com>,
  postmast.root.admi.gov@iname.com (blargg) (postmaster@nospam.gov)
wrote:
>
> In article <7tib85$6t5@library2.airnews.net>, "Bill Wade"
> <bill.wade@stoner.com> wrote:
>
> > Once a namespace alias has been defined it can be used anywhere the
original
> > name could be used.
>
> Really?
>
>     namespace X {
>         // ...
>     }
>
>     namespace Y = X;
>
>     namespace Y {
>         // ...
>         // added to namespaces X (and Y)
>     }
>
> Do you mean anywhere *except* in re-opening a namespace?

That's right -- a namespace extension cannot use a namespace-alias,
only an original-namespace-name (7.3.1p1,3).
--
William M. Miller, wmm@fastdial.net
OnDisplay, Inc. (www.ondisplay.com)


Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: jivecat@my-deja.com
Date: 1999/10/13
Raw View
Thanks to all who replied.  I do not have access to the actual
standard, but from everything else I looked at (the "bible" -- i.e.
Stroustrup's "The C++ Programming Language", Lippman, etc.) did not
explicitly say you could NOT qualify a function definition with an
alias.  Unfortunately neither did anything say you could, either.
Hence my question.

You folks have thus managed to clear up one bugging issue for me.
Thanks again.

As a side note, the gcc compiler (2.95) -- the most conformant compiler
I know of -- accepted the alias-scoped function defintion.



Sent via Deja.com http://www.deja.com/
Before you buy.

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Darin Adler" <darin@bentspoon.com>
Date: 1999/10/11
Raw View
jivecat@my-deja.com wrote:

> My question is: what does the Standard say about this?  Can you use
> aliases to define a function (in which case the Borland compiler is a
> bit too jittery)?  Or is this indeed illegal (in which the MSVC is a
> little too slack)?

My reading of the standard indicates that you can use a namespace alias to
qualify a function definition. I think that the Borland compiler is
incorrect to reject this.

The compiler I use most often, Metrowerks CodeWarrior Pro 5.2, gets this
right, too. (Correction to my previous posting: A typo in the original
posted code had me a bit confused.)

    -- Darin

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Bill Wade" <bill.wade@stoner.com>
Date: 1999/10/11
Raw View

jivecat@my-deja.com wrote in message <7td0gb$udu$1@nnrp1.deja.com>...

>My question is: what does the Standard say about this?  Can you use
>aliases to define a function ...

Once a namespace alias has been defined it can be used anywhere the original
name could be used.




      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]








Author: hektor_sontag@my-deja.com
Date: 1999/10/11
Raw View
Why not define your class directly in the namespace, instead
of "injecting" them with the resolution operators? I.e., instead of:

Namespace1::Namespace2::ClassName::FuncName1(void)
{
}

Namespace1::Namespace2::ClassName::FuncName2(void)
{
}


Use:

namespace Namespace1 {
   namespace Namespace2 {
       ClassName::FuncName1(void)
       {
       }
       ClassName::FuncName2(void)
       {
       }
   }
}

In answer to you question, however, I do not know if the standard
specifically bars using aliases in namespace scope resolution when
defining a function. I sure would like to know, however!!!  Anyone out
there have any idea?

- hektor

In article <7td0gb$udu$1@nnrp1.deja.com>,
  jivecat@my-deja.com wrote:
> Hi all.  I'm messing around with Borland C++ Builder 4.0.  My normal
> compiler is MSVC 6.0.  With the Borland compiler, I am getting lots of
> errors with the use of aliases in my function definitons:
>
> // SomeClass.h ///////////////////////////////////
> namespace mySuperLongAndLengthyNameSpaceName {
>     class SomeClass {
>
>     public:
>         void someFunction(void);
>     }
> }
>
> // SomeClass.cpp /////////////////////////////////
> #include "SomeClass.h"
>
> namespace myNs = mySuperLongAndLengthyNameSpaceName;
>
> void myNS::SomeClass::someFunction(void)
> {
> }
>
> //////////////////////
>
> The Borland compiler does not like my function definition as given
> above.  If I replace "myNS" with the actual namespace name in the
> function definition, then everything is OK.  MSVC gave me no trouble
> with the alias used in the above manner.
>
> My question is: what does the Standard say about this?  Can you use
> aliases to define a function (in which case the Borland compiler is a
> bit too jittery)?  Or is this indeed illegal (in which the MSVC is a
> little too slack)?
>


Sent via Deja.com http://www.deja.com/
Before you buy.

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]








Author: postmast.root.admi.gov@iname.com (blargg) (postmaster@nospam.gov)
Date: 1999/10/11
Raw View
In article <7tib85$6t5@library2.airnews.net>, "Bill Wade"
<bill.wade@stoner.com> wrote:

> jivecat@my-deja.com wrote in message <7td0gb$udu$1@nnrp1.deja.com>...
>
> >My question is: what does the Standard say about this?  Can you use
> >aliases to define a function ...
>
> Once a namespace alias has been defined it can be used anywhere the original
> name could be used.

Really?

    namespace X {
        // ...
    }

    namespace Y = X;

    namespace Y {
        // ...
        // added to namespaces X (and Y)
    }

Do you mean anywhere *except* in re-opening a namespace?


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: jivecat@my-deja.com
Date: 1999/10/05
Raw View
Hi all.  I'm messing around with Borland C++ Builder 4.0.  My normal
compiler is MSVC 6.0.  With the Borland compiler, I am getting lots of
errors with the use of aliases in my function definitons:

// SomeClass.h ///////////////////////////////////
namespace mySuperLongAndLengthyNameSpaceName {
    class SomeClass {

    public:
        void someFunction(void);
    }
}

// SomeClass.cpp /////////////////////////////////
#include "SomeClass.h"

namespace myNs = mySuperLongAndLengthyNameSpaceName;

void myNS::SomeClass::someFunction(void)
{
}

//////////////////////

The Borland compiler does not like my function definition as given
above.  If I replace "myNS" with the actual namespace name in the
function definition, then everything is OK.  MSVC gave me no trouble
with the alias used in the above manner.

My question is: what does the Standard say about this?  Can you use
aliases to define a function (in which case the Borland compiler is a
bit too jittery)?  Or is this indeed illegal (in which the MSVC is a
little too slack)?



Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]