Hi suresh, Sorry about all the emails, but my gcc dev machines were unavailable to me. Ok, so the issue is that even though the templates are type equivalent, literal integer values create an explicit specialization. I just became busy with work, so I'm unable to find the spec paragraph that states this with non-type template parameters. I believe that is the issue you're seeing. corey On 6/21/05, Suresh T <suresh.t@xxxxxxxxxxx> wrote: > > hi corey, > > The correct error message and the corresponding code is attached > Sorry for the previous incorrect mail!! > > >> Can you tell me what the actual gcc error is? > > // -------------- The error message ----------------- > test_word.cpp: In member function `unsigned int outer<sz>::read(unsigned > int) > [with unsigned int ssz = 8, unsigned int sz = 32]': > /usr/include/c++/3.2.3/ostream:130: instantiated from > `std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, > _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = > std::char_traits<char>]' > test_word.cpp:73: instantiated from here > test_word.cpp:57: no matching function for call to `dummy<32>::get(unsigned > int&)' > > > Note : > 1. The line 57( shown in error )corresponds to the place where the > static_cast is used in the code below in the outer class > The line 73 corresponds to the instantiation in main > 2. If dummy is created (inside outer) with a hardcoded value rather > than using the "sz" templ parameter of outer, there will not be an error > 3. I have found a strange workaround to the problem. If you use the > same function names in both classes the > compiler goes ahead and code works ( i checked that the right > function is called) . But since this is strange and without any logical > explanation i am interested in the correct solution > > > /// ------------------ The used sample test_word code is below > -------------------------- > #include <iostream> > using namespace std; > > template <std::size_t sz> > class dummy{ > public: > > dummy(){ } > > template<std::size_t ssz> > unsigned int get(unsigned int index){ > return 1; > } > > }; > > > template <std::size_t sz> > class outer{ > public: > > outer() { } > > template<std::size_t ssz> > unsigned int read(unsigned int index){ > return (static_cast<dummy_type > (obj)).get<ssz>(index); > } > > typedef dummy<sz> dummy_type; //replacing this line with > typedef dummy<N> dummy_type .... ..... > dummy<sz> obj; //and this > line with dummy<N> obj will work where N = any numeric value > }; > > int > main (int argc, char* argv[]) > { > outer<32> o_obj; > std::cout<<"\n o_obj.read() :"<<o_obj.read<8>(1); > return 1; > } > > --------------------------------------------------------------------------------------------------------- > > Suresh.T > > > > > > > > To > Suresh T/BTC/SC/PHILIPS@PHILIPS > cc > corey taylor gcc-help@xxxxxxxxxxx > Subject > Sent by: Re: template class within another : > gcc-help-owner@xxxxx problem with gcc 3.2.3 on linux > nu.org (BUG ??) > Classification > 06/21/2005 10:01 AM > > Please respond to > corey taylor > <corey.taylor@gmail. > com> > > > > > > > Suresh, > > Can you tell me what the actual gcc error is? > > corey > > On 6/20/05, Suresh T <suresh.t@xxxxxxxxxxx> wrote: > > hi corey, > > > > >> What type of objects are contained_size and inner_object? > > > > Sorry, that was a typo (not in the actual code but in the mail that i > > sent). > > (Instead of putting the actual code, i wanted to put in a short one > > illustrating the problem!!) > > > > > > inner_object is an object of class contained (which was correct in the > > mail). This is within the class "enclosing". The "enclosing" > > class has a template parameter "size" and contained is created using > that > > size. WHICH IS WHERE THE PROBLEM ORIGINATES > > as i said in the previos mail. > > > > i.e., contained<size> inner_object; > > > > and there was a typo in the static_cast . It should be : > > (static_cast<contained <size> >( inner_object) ) .fun_inner(); > > > > > > I hope i can get some answer as this looks very gcc specific. > > > > Thanks in advance > > > --------------------------------------------------------------------------------------------------------- > > > > > Warm Regards, > > Suresh.T > > > > > > > > > > > > > > > > > To > > Suresh T/BTC/SC/PHILIPS@PHILIPS > > > cc > > corey taylor gcc-help@xxxxxxxxxxx > > > Subject > > Sent by: Re: template class within another > : > > gcc-help-owner@xxxxx problem with gcc 3.2.3 on linux > > nu.org (BUG ??) > > > Classification > > 06/20/2005 08:17 PM > > > > Please respond to > > corey taylor > > <corey.taylor@gmail. > > com> > > > > > > > > > > > > > > Suresh, > > > > What type of objects are contained_size and inner_object? > > > > corey > > > > On 6/20/05, Suresh T <suresh.t@xxxxxxxxxxx> wrote: > > > hi, > > > > > > I need to use a template class object within another template class. > > > Specifically gcc (3.2.3 on linux) gives me a problem when the INNER > > > TEMPLATE OBJECT IS CREATED USING THE TEMPLATE PARAMETER OF THE > ENCLOSING > > > CLASS and when i call the inner class object function from the > enclosing > > > class object function.. > > > AS this works fine in MS VC7 so i wanted to know if this is some bug > in > > > gcc > > > > > > Example : > > > In the below example the "enclosing" class contains an object of > > > "contained" class. The contained object is created using the > > > template parameter of "enclosing" class. When the "enclosing" class > > > function is called, we call the function of the inner object. > > > > > > template <std::size_t size> > > > class contained { > > > public: > > > template <std::size_t sub_size> > > > int func_inner(){ ... } > > > > > > }; > > > > > > template < std::size_t size> > > > class enclosing { > > > > > > public: > > > > > > template <std::size_t sub_size> > > > int func_enclose(){ ... > > > > > > return > > > (static_cast<contained_size>( inner_object) ) .fun_inner(); > > > > // > > > =================THIS GIVES AN ERROR ======================== > > > MARK1 > > > } > > > > > > contained<size> inner_object; // ============== THIS IS > THE > > > ORIGIN OF ERROR ? ===================== MARK2 > > > > > > }; > > > > > > > > > Note : The error disappears if i use a specific value when creating the > > > inner_object ( MARK 2 above) > > > That is instead of "contained<size> inner_object" if i use "contained > > <N> > > > inner_object" where N is any number like 32. > > > (Even in that case i need to use a static_cast ( see MARK 1) to remind > > the > > > compiler of the data type of inner_object otherwise > > > the compiler gives an error which i find strange.) > > > > > > I cant use a specific value for the inner object as it should take it > > from > > > the enclosing class template parameter. Since this is > > > not working i would greatly appreciate if someone can tell me whether > > this > > > is a gcc bug or if i need to do something special to let the compiler > > > know what i am trying to do. > > > > > > Thanks & > > > > > > --------------------------------------------------------------------------------------------------------- > > > > > > > > > Warm Regards, > > > Suresh.T > > > > > > > > > > > > > > > > > >