Topic: class member re-declaration redundant?


Author: andreytarasevich@hotmail.com (Andrey Tarasevich)
Date: Tue, 3 Sep 2002 16:41:33 +0000 (UTC)
Raw View
Victor Bazarov wrote:
> ...
> Multiple declarations are OK, multiple definitions (a typedef
> is a definition) are not.
> ...

It probably worth noting that 'typedef' is a special kind of definition.
Multiple typedef-definitions are OK as long as they don't try to change
the type to which the typedef-name already refers (see 7.1.3/2).

Best regards,
Andrey Tarasevich,
Brainbench C and C++ Programming MVP

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: sdouglass@arm.com (scott douglass)
Date: Thu, 5 Sep 2002 14:16:09 +0000 (UTC)
Raw View
"Radoslav Getov" <rgetov@ultraheap.com> wrote...
> I only judge this by my compiler (MSVC60), but it allowes this syntax:
>
> class Class
> {
>    void member();
> };
>
>
> void Class::member();    // <<<<< (1)
>
> Now, if the Class's definition is not visible, it regects (1).

The line marked (1) is illegal even if we've seen Class's definition.  9.=
3/2
specifically disallows it:

>>
Except for member function definitions=20
that appear outside of a class definition, and except for explicit
specializations of template member func=AD
tions (14.7) appearing outside of the class definition, a member function=
 shall
not be redeclared.=20
<<

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Victor Bazarov" <vAbazarov@dAnai.com>
Date: 28 Aug 2002 18:05:11 GMT
Raw View
"Radoslav Getov" <rgetov@ultraheap.com> wrote...
> I only judge this by my compiler (MSVC60), but it allowes this syntax:
>
> class Class
> {
>    void member();
> };
>
>
> void Class::member();    // <<<<< (1)
>
> Now, if the Class's definition is not visible, it regects (1).
>
> Some time ago I proposed here the allowance of forward class
> partial declarations, which would make (1) legal even if 'Class'
> is not visible. IMO that would allow better encapsulation and
> reduced dependencies, etc.

No, it would introduce trouble becuase the compiler won't be
able to generate correct code (think of offsets to members in
an object, without full definition of the type it is impossible
to create correct addressing).

> But what I am wondering is why (1) is allowed at all? As far as I can
> tell (unlike e.g. multiple typedefs), it is ALWAYS redundant.

Multiple declarations are OK, multiple definitions (a typedef
is a definition) are not.

> Should this probably be depreciated in some next standard revision?

It doesn't hurt anybody, does it?

IMHO

Victor
--
Please remove capital A's from my address when replying by mail


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rgetov@ultraheap.com (Radoslav Getov)
Date: Fri, 21 Jun 2002 15:38:05 GMT
Raw View
HI all,

I only judge this by my compiler (MSVC60), but it allowes this syntax:

class Class
{
   void member();
};


void Class::member();    // <<<<< (1)

Now, if the Class's definition is not visible, it regects (1).

Some time ago I proposed here the allowance of forward class
partial declarations, which would make (1) legal even if 'Class'
is not visible. IMO that would allow better encapsulation and
reduced dependencies, etc.

But what I am wondering is why (1) is allowed at all? As far as I can
tell (unlike e.g. multiple typedefs), it is ALWAYS redundant.

Should this probably be depreciated in some next standard revision?

Radoslav Getov
www.ultraheap.com

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]