Solved

Control statements during template construction

Posted on 2009-07-11
4
201 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

919 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now