473,480 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with inner class of a class template as member function returntype

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<intc;
c.show();
}
~
~
~
Jan 8 '08 #1
4 1630
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<intc;
c.show();
}
~
Seems fine to me. What error do you get from gcc?

BTW, Comeau online accepts it as well.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 8 '08 #2
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<intc;
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)
Jan 8 '08 #3
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<intc;
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 8 '08 #4
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<intc;
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
Jan 8 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3316
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
0
2372
by: tyousaf | last post by:
Hi i am new to mysql and mysql++, i have installed mysql server, it is running fine. i also installed "mysql++-1.7.9gcc3.2-2.i386.rpm" (i have gcc 3.3) , first of all as the readme file says to do...
7
2109
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
5
1545
by: Gernot Frisch | last post by:
class Q { public: template<class T>void foo(){} }; main() { Q q; q.foo<int>(); // error
1
2112
by: darkstorm | last post by:
Please check this program...When I compiles it in VC.net, it gives the following error: =============== Common\Lib\PList.h(115): error C2440: '=' : cannot convert from 'ListNode *' to...
13
9627
by: kamaraj80 | last post by:
Hi I am using the std:: map as following. typedef struct _SeatRowCols { long nSeatRow; unsigned char ucSeatLetter; }SeatRowCols; typedef struct _NetData
2
2293
by: pookiebearbottom | last post by:
Just trying to learn some things about templates. Was wondering how boost::tupple really works, but the headers were a bit confusing to me. I know you get do something like the following, just...
4
7980
by: zfareed | last post by:
#include <iostream> #include <fstream> using namespace std; template<class ItemType> class SortedList { private:
5
2434
by: Daniel T. | last post by:
The goal is to make a friend function of an inner template class... template < typename T > class Foo { public: class Bar { friend bool operator==( const typename Foo<T>::Bar& lhs, const...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4483
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2985
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.