 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Oskar Enoksson Guest
|
Posted: Sat Jan 17, 2004 1:31 am Post subject: Q: template specialization case |
|
|
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
|
Posted: Sat Jan 17, 2004 11:32 pm Post subject: Re: Q: template specialization case |
|
|
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 |
|
 |
|
|
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
|
|