This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: is it a bug or do i miss something?(about conflicts between template parameter and data member)


if i made some stupid mistakes, please tell me ,3x

On Sat, 2007-11-17 at 12:51 +0800, éææ wrote:
> gcc version:
> 
> g++ (GCC) 4.1.1 20061011 (Red Hat 4.1.1-30)
> Copyright (C) 2006 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is
> NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE.
> 
> ----------------source code------------------------------------
> #include <stdio.h>
> 
> class Base {
> public:
>    int type;
>    Base(int type) {this->type = type;}
>    void showtype() {printf("%d\n",type);}
> 
> };
> 
> template<int type>
> class Derived : public Base {
> public:
>     Derived();
> };
> 
> template<int type>
> Derived<type>::Derived()
> : Base(type)
> {
> }
> 
> 
> template<int TYPE>
> class Derived2 : public Base {
> public:
>     Derived2();
> };
> 
> template<int TYPE>
> Derived2<TYPE>::Derived2()
> : Base(TYPE)
> {
> }
> 
> enum {
>     ZERO = 0,
>     NONZERO = 1,
> };
> 
> 
> typedef Derived<NONZERO> NonZeroClass;
> typedef Derived2<NONZERO> NonZeroClass2;
> 
> int main() {
>     NonZeroClass tmp;
>     tmp.showtype();
> 
>     NonZeroClass2 tmp2;
>     tmp2.showtype();
> }
> -----------------source code end-------------------------------
> 
> ----------------output------------------------------
> 165643296
> 1
> ---------------output end----------------------------
> 
> the only difference between Derived and Derived2 is that
> Derived's template parameter is the same as Base's data member(they are
> both type).
> 
> The output to me is a surprise. i do not know whether it is a bug, so
> just post it here
> 
> 3x for your attention.
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]