Solved

Control statements during template construction

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

760 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

20 Experts available now in Live!

Get 1:1 Help Now