rami wrote:
> I have some code which does following thing
> template<class X, unsigned ID = 0>
> struct SomeStruct
> {
> template<class X>
> static SomeStruct<X, ID + 1>& SomeFunc();
> ..
> ..
> ..
> ..
> };
>
> It has more than one overloads of SomeFunc and some other function
> which have same return types.
>
> Well i can understand the code pretty much but what i need to
> understand is why ID is being used and increamented everytime on the
> return?
How can anyone tell without seeing how the ID argument is used?
> I think its to avoid the compiler to use the same instiation - but i go
> blank when i try to expand on my thought
It is usually to use the other instantiation (not to avoid using the same
instantiation). IOW, it's to _chain_ the classes:
SomeStruct<int,10> blah;
blah.SomeFunc<int>().SomeFunc<int>().SomeFunc<int> ();
will cause the instantiation of SomeStruct<int,10> and [probably] also
SomeStruct<int,11>, SomeStruct<int,12>, and SomeStruct<int,13> since they
are the return value types of the three calls.
> Any help would be appreciated, in case the example is vague i can maybe
> post more..
You don't have to post more for now. Try to understand the role of 'ID'
and how advancing it achieves some goal and what that goal might be. If
you do fail to understand it, post again, with more concrete code and
questions.
Good luck!
V