Solved

Control statements during template construction

Posted on 2009-07-11
4
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

710 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