Topic: namespace and typedef
Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/02/19 Raw View
Nathan Myers wrote:
>
> Haitao Zhao <jstwo@usa.net> wrote:
> >in global namespace:
> >typedef int BOOL
> >class a { public: virtual BOOL foo(); };
> >namespace MyBool {
> > typedef bool BOOL
> > struct b : a { bool foo(); };
> >}
> >when I compile it , the compiler didn't give any error...
> >Will this kind of define cause some potential bug or it's just works?
>
> Your compiler is broken. b::foo has a signature that matches a::foo(),
> but with an incompatible return type. The compiler should catch that.
I guess that the compiler doesn't support bool, and bool is
just #defined as int (a practice that I support for such
compilers).
--
Valentin Bonnard
[ 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: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1999/02/17 Raw View
Haitao Zhao <jstwo@usa.net> wrote:
>in global namespace:
>typedef int BOOL
>class a { public: virtual BOOL foo(); };
>namespace MyBool {
> typedef bool BOOL
> struct b : a { bool foo(); };
>}
>when I compile it , the compiler didn't give any error...
>Will this kind of define cause some potential bug or it's just works?
Your compiler is broken. b::foo has a signature that matches a::foo(),
but with an incompatible return type. The compiler should catch that.
--
Nathan Myers
ncm@nospam.cantrip.org http://www.cantrip.org/
[ 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: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/02/15 Raw View
Haitao Zhao <haitao@hotmail.com> writes:
> I get a problem with namespace and typedef, does anyone know the
> following valid or not?
It is not valid. You can't have a virtual function return int in the
base class, and bool in the derived class - not even if you use
similar-looking typedefs :-)
Regards,
Martin
---
[ 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: Haitao Zhao <haitao@hotmail.com>
Date: 1999/02/14 Raw View
Hi
I get a problem with namespace and typedef, does anyone know the
following valid or not?
the problem:
in global namespace, i defined a class:
class a {
public:
virtual BOOL foo();
...
};
the BOOL is typedefed as
typedef int BOOL in a header file
in namespace MyBool
namespace MyBool {
typedef bool BOOL
class b : public a
{
public:
bool foo();
....
};
}
when I compile it , the compiler didn't give any error. and when i debug
it, the debugger shows that the second version of foo() overwrites first
version of foo().
but when this two class all defined in global namespace, the compiler
will give a error that says the two foo() only different in return
type.
Will this kind of define cause some potential bug or it's just works?
Thanks in advance
haitao
---
[ 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 ]