473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Need some help with advanced templates

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?

I think its to avoid the compiler to use the same instiation - but i go
blank when i try to expand on my thought :-|

Any help would be appreciated, in case the example is vague i can maybe
post more..

Regards,
Rami

Jul 22 '05 #1
1 1197
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
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
1
by: David2511 | last post by:
Hello, I need a little help. I try to write the following architecture : an abstract template class A Two classes derived from class A : the classes B and C which are concrete. The class...
0
by: xunling | last post by:
i have a question about answering ..... this topic is "need help" what do i have to write at te topic line, !after i have klicked the "answer message" button ive tried many possibilities,...
2
by: Paul Mendez | last post by:
I really need some help Date Code ConCAT Bal_Fwd NS_Fees Amt_Coll Cur_End_Bal 1/15/2004 KW 11KW2003 $500.00 $250.00 $250.00 2/15/2004 KW 12KW2003 $300.00 $500.00 ...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
8
by: Elliot M. Rodriguez | last post by:
I am having a heckuva time debugging this, or determining why my page is behaving this way. I have a search form, that when completed, returns a datagrid. When the user selects a row (normal...
4
by: Piper707 | last post by:
I need help with using a general template which would process all tags other than the ones for which specific templates have been written. My XML looks like this: <ITEMS>...
4
by: robinsand | last post by:
My apologies to those of you who are more advanced Visual C++ .NET programmers, but I am working on a project for an MBA course that is condensed into an eight-week schedule, and I need help...
3
by: Rich Squid | last post by:
Hello Here's my basic problem: On my asp.net form page I have a DetailsView (default mode=edit) bound to a AccessDataSource control. Users can successfuly update a databound template field,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.