Solved

Control statements during template construction

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

820 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