Victor Bazarov wrote:
> Fei Liu wrote:
>> Victor Bazarov wrote:
>>> Fei Liu wrote:
>>>> Hello, I am having trouble to properly construct the 'show' function
>>>> definition. g++ 4.1.1 is giving me error messages but intel c++
>>>> compiler compiles it fine. Which one is correct?
>>>>
>>>> Fei
>>>>
>>>> #include <iostream>
>>>> using namespace std;
>>>>
>>>> template <typename T>
>>>> struct C{
>>>> struct S{
>>>> T x;
>>>> };
>>>>
>>>> S s;
>>>> S show();
>>>> };
>>>>
>>>> template <typename T>
>>>> C<T>::S C<T>::show(){
>>>> cout << s.x << '\n';
>>>> return s;
>>>> }
>>>>
>>>> int main(){
>>>>
>>>> C<int> c;
>>>> c.show();
>>>> }
>>>> ~
>>> Seems fine to me. What error do you get from gcc?
>>>
>>> BTW, Comeau online accepts it as well.
>>>
>>> V
>> g++ -fstrict-aliasing -fomit-frame-pointer -Wall -pedantic -ansi -g
>> -O0 -o templ_inner_class.o -c templ_inner_class.cpp
>> templ_inner_class.cpp:15: error: expected constructor, destructor, or
>> type conversion before 'C'
>> gcc version 4.1.2 20061115 (prerelease)
>
> Perhaps a 'typename' would silence it:
>
> template <typename T>
> typename // this here
> C<T>::S C<T>::show(){ ...
>
> V
Yeap, this is the fix for g++, thanks!
Fei
|