Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Control statements during template construction

Posted on 2009-07-11
4
Medium Priority
?
237 Views
Last Modified: 2012-05-07
Hi,

Don't suppose there is anything that can be used to help guide template construction. For example:

Thanks,
Uni
template<typename TName>
class C{
      if TName==X
            int function();
      else
            TName function();
      end if
};

Open in new window

0
Comment
Question by:Unimatrix_001
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 24831524
It seems that you are thinking of template specialization here, see http://www.cprogramming.com/tutorial/template_specialization.html for more. Otherwise, you are right, there is no such thing with templates.
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24831526
Ok, thank you once again. :)
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 31602451
:)
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24831546
Also, besides what jkr said, to reuse common template code in a conditional manner (albeit at pre-processor time) you can use old-fashioned # preprocessor directives and include in separate files with/without a given #define.

It may be a little messy and I don't do it personally, I prefer the templates to be clean (as possible).
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question