Topic: namespace
Author: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Date: 11 Jul 1994 19:48:31 GMT Raw View
LS> Is it legal to declare
LS>
LS> class X
LS> {
LS> void foo();
LS> };
LS>
LS>
LS> and define X::foo
LS>
LS>
LS> namespace X
LS> {
LS> void foo()
LS> {
LS> //..
LS> }
LS> };
I think the intention of the original quesion was:
Is it allowed to declare a class X (with classbody)
and then to implement its methods in a namespace X
(this avoiding X::)
This idea has already occured in this thread:
Re: Language Question: Why privates in header
but I can't remember the answer.
In my OPINION it would be a goos idea to allow it.
Often the implementation of a class X is at one place.
Always having to qualify with X:: is annoying and
not easy to read:
X::EnumType X::static_var = X::some_enumerator;
X::EnumType X:: foo()
{ // in the fctbody there is no need for X:: !
return static_var;
}
void X:: g() {}
void X:: h() {}
void X:: i() {}
Isn't whis clearer to place the implementation into
the namespace of the _class_ X ?:
namespace X { // or namespace class X
// if this is syntactically clearer
EnumType static_var = some_enumerator;
EnumType foo ()
{
return static_var;
}
void g() {}
void h() {}
void i() {}
}; // X
Ulf Schuenemann
--------------------------------------------------------------------
Ulf Sch nemann
Institut f r Informatik, Technische Universit t M nchen.
email: schuenem@informatik.tu-muenchen.de
Author: ldang@bnr.ca (Student)
Date: Thu, 7 Jul 94 16:51:02 GMT Raw View
Is it legal to declare
class X
{
void foo();
};
and define X::foo
namespace X
{
void foo()
{
//..
}
};
???
-------
LD.
Author: davem@eden.rutgers.edu (David Miller)
Date: 7 Jul 94 19:39:03 GMT Raw View
Student (ldang@bnr.ca) wrote:
: Is it legal to declare
: class X
: {
: void foo();
: };
: and define X::foo
: namespace X
: {
: void foo()
: {
: //..
: }
: };
I don't think so because your class X is in the "global"
namespace and your function foo is just a plain function in namespace
X. They are two different things. I think the affect you want is:
namespace X
{
class X
{
void foo() { // whatever }
}
}
Then later in your program:
using X;
X a;
X b;
a.foo();
b.foo();
I don't know if the syntax is right but you get the idea.
Later,
David S. Miller
davem@eden.rutgers.edu
: ???
: -------
: LD.
Author: rad6938@tntech.edu (Rad)
Date: 8 Jul 94 00:05:52 -0600 Raw View
In article <Jul.7.15.39.02.1994.14505@er2.rutgers.edu>, davem@eden.rutgers.edu (David Miller) writes:
> Student (ldang@bnr.ca) wrote:
> : Is it legal to declare
>
> : class X
> : {
> : void foo();
> : };
>
>
> : and define X::foo
>
>
> : namespace X
> : {
> : void foo()
> : {
> : //..
> : }
> : };
>
>
> I don't think so because your class X is in the "global"
> namespace and your function foo is just a plain function in namespace
> X. They are two different things. I think the affect you want is:
> ...
Also I think the standard states that "the identifier used as a global
namespace-name cannot be used as the name of any other global namespace,
template, type, function, object, or value in the given program."
This means if you have a namespace X you can't have a class X... unless I
misunderstand this or unless it's changed in a more recent draft.
----------------------------------------------------------------------------
Richard Deken Graduate student in electrical engineering
Tennessee Technological University
Internet: rad6938@gemini.tntech.edu Cookeville, TN, USA