简体   繁体   English

C ++模板化为特定类型,而无需使用传统的模板专业化

[英]c++ templating to specific type without using traditional Template Specialization

template <typename T_>
class my_class {
public:
       typedef T_   value_type;
       typedef T_ * pointer;

I'm developing a templated class, however because the C++ error detection and intellisence suck for templated stuff, is there a way I can set the template to example int to get the benefit of intellisence, and then when I'm done development just switch it back and fix a couple errors? 我正在开发一个模板化类,但是由于C ++错误检测和智能化吸引了模板化的东西,有没有一种方法可以将模板设置为example int以获得智能化的好处,然后在完成开发后切换它回来并修复几个错误?

I still want my code to be generic and re-writing it as Template Specialization is too much work. 我仍然希望我的代码是通用的,并重新编写它,因为Template Specialization太多了。

I want to be able to do something like 我希望能够做类似的事情

template <typename T_ = int>
class my_class {
public:
       typedef T_   value_type;
       typedef T_ * pointer;

I'm not completely sure I understand what you're trying to accomplish, but you could typedef T_ to int in the class and disable the template statement, either through the pre-processor or commenting it out. 我不能完全确定我了解您要完成的工作,但是您可以通过预处理器或注释掉typedef T_int并禁用模板语句。

#ifndef NO_MY_CLASS_TEMPLATE
template <typename T_ = int>
#endif
class my_class {
#ifdef NO_MY_CLASS_TEMPLATE
       typedef int T_;
#endif
public:
       typedef T_   value_type;
       typedef T_ * pointer;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM