当我编写类模板并需要完全特化这些类的成员时,Doxygen无法识别该特化 - 它仅记录通用定义或(如果只有特化)最后一个定义。以下是一个简单的例子:
===MyClass.hpp===
在这种情况下,foo()将被记录为打印“通用foo”,INT_CONST将被记录为设置为5,没有提及特化情况,TTYPE_CONST将被记录为设置为'a',没有提及3.141,也没有指示'a'是一个特殊情况。
我需要能够记录特化情况 - 要么在>的文档中,要么在< MyClass>,>的新页面上。我该怎么做?Doxygen是否能够处理这个问题?我可能在声明/代码结构方面做错了什么,导致Doxygen无法理解我的意图?
我应该注意两个相关的情况:
A)对于模板函数,特化工作正常,例如:
这将记录
B) 如果我重新声明整个模板,即
有什么建议吗?非常感谢 :)
--Ziv
===MyClass.hpp===
#ifndef MYCLASS_HPP
#define MYCLASS_HPP
template<class T> class MyClass{
public:
static void foo();
static const int INT_CONST;
static const T TTYPE_CONST;
};
/* generic definitions */
template<class T>
void MyClass<T>::foo(){
printf("Generic foo\n");
}
template<class T>
const int MyClass<T>::INT_CONST = 5;
/* specialization declarations */
template<> void MyClass<double>::foo();
template<> const int MyClass<double>::INT_CONST;
template<> const double MyClass<double>::TTYPE_CONST;
template<> const char MyClass<char>::TTYPE_CONST;
#endif
=== MyClass.cpp ===
#include "MyClass.hpp"
/* specialization definitions */
template<>
void MyClass<double>::foo(){
printf("Specialized double foo\n");
}
template<> const int MyClass<double>::INT_CONST = 10;
template<> const double MyClass<double>::TTYPE_CONST = 3.141;
template<> const char MyClass<char>::TTYPE_CONST = 'a';
在这种情况下,foo()将被记录为打印“通用foo”,INT_CONST将被记录为设置为5,没有提及特化情况,TTYPE_CONST将被记录为设置为'a',没有提及3.141,也没有指示'a'是一个特殊情况。
我需要能够记录特化情况 - 要么在>的文档中,要么在< MyClass>,>的新页面上。我该怎么做?Doxygen是否能够处理这个问题?我可能在声明/代码结构方面做错了什么,导致Doxygen无法理解我的意图?
我应该注意两个相关的情况:
A)对于模板函数,特化工作正常,例如:
/* functions that are global/in a namespace */
template<class T> void foo(){ printf("Generic foo\n"); }
template<> void foo<double>(){ printf("Specialized double foo\n"); }
这将记录
foo<T>()
和foo<double>()
。B) 如果我重新声明整个模板,即
template<> class MyClass<double>{...};
,那么MyClass<double>
将获得自己的文档页面,作为一个单独的类。但这意味着实际上声明了一个全新的类 - 如果声明了MyClass<double>
本身,则MyClass<T>
和MyClass<double>
之间没有任何关系。因此,我必须重新声明类及其所有成员,并重复所有为MyClass<double>
专门化的类成员定义,以使它们看起来像使用同一模板。非常笨拙,感觉像是一个临时解决方案。有什么建议吗?非常感谢 :)
--Ziv