How do you do old fashion CPP hackery in templates?

P

px122000

Perhaps I am misusing template but I want to write a template that
creates a class and in the class are three functions, <foo>_set,
<foo>_clr, <foo>_tst. So if I invoke the template with a name like
'mask', three methods would be created called mask_set, mask_clr, and
mask_tst. In the old CPP world, you could use ## (or was it just #?).
I don't think I can use that in templates because the CPP pass is
before the compiler.

Thanks
 
V

Victor Bazarov

Perhaps I am misusing template but I want to write a template that
creates a class and in the class are three functions, <foo>_set,
<foo>_clr, <foo>_tst. So if I invoke the template with a name like
'mask', three methods would be created called mask_set, mask_clr, and
mask_tst. In the old CPP world, you could use ## (or was it just #?).
I don't think I can use that in templates because the CPP pass is
before the compiler.

You're correct. This preprocessor trick is still there for you to use,
templates, however, are not meant for that.

V
 
L

Lars Tetzlaff

Perhaps I am misusing template but I want to write a template that
creates a class and in the class are three functions, <foo>_set,
<foo>_clr, <foo>_tst. So if I invoke the template with a name like
'mask', three methods would be created called mask_set, mask_clr, and
mask_tst. In the old CPP world, you could use ## (or was it just #?).
I don't think I can use that in templates because the CPP pass is
before the compiler.

Thanks

Question: why do you want to create functions named like that and not
simply set, clr, tst?
In C you had to do such things because there was no overloading. But do
you need it in C++?

Lars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top