G
graham
Hi,
can anybody please explain why the following prints 4, 3, 2, 1, 0 and
not 0, 1, 2, 3, 4
I like what this does but don't understand why the values are assigned
the values in the order they are?
cheers
Graham
class type2intbase {
template <typename T>
friend struct type2int;
static const int next() {
static int id = 0; return id++;
}
};
template <typename T>
struct type2int {
static const int value() {
static const int id = type2intbase::next(); return id;
}
};
struct foo{};
struct foo1{};
struct foo2{};
struct foo3{};
struct foo4{};
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
type2int<foo> zero;
type2int<foo1> one;
type2int<foo2> two;
type2int<foo3> three;
type2int<foo4> four;
cout << zero.value() << " " << one.value() << " " << two.value()
<< " " << three.value() << " " << four.value() << " " << endl;
return 0;
}
can anybody please explain why the following prints 4, 3, 2, 1, 0 and
not 0, 1, 2, 3, 4
I like what this does but don't understand why the values are assigned
the values in the order they are?
cheers
Graham
class type2intbase {
template <typename T>
friend struct type2int;
static const int next() {
static int id = 0; return id++;
}
};
template <typename T>
struct type2int {
static const int value() {
static const int id = type2intbase::next(); return id;
}
};
struct foo{};
struct foo1{};
struct foo2{};
struct foo3{};
struct foo4{};
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
type2int<foo> zero;
type2int<foo1> one;
type2int<foo2> two;
type2int<foo3> three;
type2int<foo4> four;
cout << zero.value() << " " << one.value() << " " << two.value()
<< " " << three.value() << " " << four.value() << " " << endl;
return 0;
}