0
我陷入了部分模板實現中,想法是提供一個在編譯時使用枚舉選擇的類(生成器)類的定義,我也想提供文件的名稱和一個班級名稱從工廠單身管理。但這不是編譯,我正在嘗試幾個小時,但我看不出我做錯了什麼。 這是代碼:C++ 11 -Template MetaProgramming - 錯誤:部分專業化中未使用的模板參數
enum class BuildersType
{
ComunicationBuilder
};
//class definition
template<BuildersType, class ... Args>
class BuiderType;
//class implementation
template<const char * const FILENAME , const char * const CLASSNAME, class ClassToConfigurate>
class BuiderType<BuildersType::ComunicationBuilder,const char * const ,const char * const ,ClassToConfigurate>
{
public:
};
template<const char * const FILENAME , const char * const CLASSNAME>
class AnotherBuilder
{
};
namespace Test
{
static constexpr char FILENAME []="aFileName";
static constexpr char CLASSNAME []="ClassName";
class TestClass{};
}
int main()
{
BuiderType<BuildersType::ComunicationBuilder,Test::FILENAME,Test::CLASSNAME,Test::TestClass> aBuilder;
AnotherBuilder<Test::FILENAME,Test::CLASSNAME> aAnotherBuilder;
return 0;
}
的編譯輸出中:
Error: template parameters not used in partial specialization:
class BuiderType<BuildersType::ComunicationBuilder,const char * const ,const char * const ,ClassToConfigurate>
^
main.cpp:14:7: error: 'FILENAME'
main.cpp:14:7: error: 'CLASSNAME'
在這個時間我真的累了,我要求幫助。 Thx // =========================================== ========== 爲了簡單起見,我將發佈的代碼與解決方案:
enum class BuildersType
{
ComunicationBuilder
};
//class definition
//Add here definition here of the templates non type arguments
template<BuildersType, const char * const FILENAME , const char * const CLASSNAME,class ... Args>
class BuiderType;
//class implementation
template<const char * const FILENAME , const char * const CLASSNAME, class ClassToConfigurate, class ... Args>
class BuiderType<BuildersType::ComunicationBuilder,FILENAME , CLASSNAME ,ClassToConfigurate,Args...>
{
public:
};
template<const char * const FILENAME , const char * const CLASSNAME>
class AnotherBuilder
{
};
namespace Test
{
static constexpr char FILENAME []="aFileName";
static constexpr char CLASSNAME []="ClassName";
class TestClass{};
}
int main()
{
BuiderType<BuildersType::ComunicationBuilder,Test::FILENAME,Test::CLASSNAME,Test::TestClass> aBuilder;
AnotherBuilder<Test::FILENAME,Test::CLASSNAME> aAnotherBuilder;
return 0;
}
THX,我dindt注意這個! thx –
@roalz:哈哈......每一個,謝謝:D – Pixelchemist
@Pixelchemist呃呃,對不起,這是我的癡迷:-P – roalz