Are you sure? I can compile your code even when the #define NOT_WORKING is commented out or not. However I get an unreferenced g variable when it is commented out.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
template <typename C, int cnt>
struct Definer
{
static const C d = cnt - 1;
Definer<C, cnt-1> f;
C const& lookup(int index)
{
if (index == (cnt - 1))
return d;
return f.lookup(index);
}
};
template <typename C>
struct Definer <C, 0>
{
static const C d = 0;
C const& lookup(int index)
{
throw 18;
}
};
i
Dont you think the "typename" should be replaced with "class" ?
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Dont you think the "typename" should be replaced with "class" ?
Why is that?
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Why is that?
Ah.. my bad, sorry I was thinking of somthing else.:confused:
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
You may have misunderstood me. You seem to have it backwards.
Without doing anything to the program, it will not link.
If you comment out the #define NOT_WORKING, then the program links and runs.
I'm using g++ 4.0.1 on a Mac as well as xlC version 8 on AIX to test with. Both agree in both cases.
Thanks for helping.
No. I am sure I have not misunderstood. It links and runs allright in both the cases. Check if you have posted the correct code.
These are the outputs. #define commented out
0
1
2
3
Press any key to continue
#define not commented out
0
1
2
3
0
1
2
3
Press any key to continue
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115