C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Q: template specialization case

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Oskar Enoksson
Guest





PostPosted: Sat Jan 17, 2004 1:31 am    Post subject: Q: template specialization case Reply with quote




I'm wondering if the following code is safely compliant with the ANSI
standard, and also if it works with todays unix compilers?

It works without warnings on gcc 3.3.2, even with flags --ansi
--pedantic -Wall.

Thanks!
/Oskar

// Begin tst.cpp

template<class T>
struct foo {
int q() { return 1; }
};

template<class T, int N>
struct foo<T[N]> {
int q() { return N; }
};

#include<iostream>
using namespace std;

int main() {
foo<float> x1;
foo<float[5]> x2;
foo<float*> x3;
foo<float[]> x4;

cout<<
x1.q()< x2.q()< x3.q()< x4.q()< }

// End tst.cpp

The output of this program should be
1
5
1
1


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Thomas Mang
Guest





PostPosted: Sat Jan 17, 2004 11:32 pm    Post subject: Re: Q: template specialization case Reply with quote





Oskar Enoksson schrieb:

Quote:
I'm wondering if the following code is safely compliant with the ANSI
standard, and also if it works with todays unix compilers?


// Begin tst.cpp

template<class T
struct foo {
int q() { return 1; }
};

template struct foo int q() { return N; }
};

#include<iostream
using namespace std;

int main() {
foo foo<float[5]> x2;
foo<float*> x3;
foo<float[]> x4;

cout
x1.q()< x2.q()< x3.q()< x4.q()< }

The template part is fine, the main part is fine, but you also have to
#include fine program.

regards,

Thomas

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.