當我編寫類模板並需要完全專門化這些類的成員時,Doxygen無法識別專業化 - 它只記錄通用定義或(如果只有專業化)最後的定義。這裏有一個簡單的例子:Doxygen for C++模板類成員專業化
=== 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<T>
的文檔中,或在MyClass<double>
,MyClass<char>
的新頁面上。我該怎麼做呢? 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>
的課程成員的定義,以使其看起來好像他們使用的是相同的模板。非常尷尬,感覺就像一個kludge解決方案。
對此提出建議?謝謝了:)
--Ziv