我想喜歡的一類: template < typename ...Whatever >
class MyClass
{
public:
static constexpr bool has_default_ctr = Something;
// I want this only if "has_default_ctr" is "true".
MyClass();
這個問題類似於: c++ template specialization for all subclasses 現在我有一個模板類的成員函數,它需要根據類模板的基類來做不同的事情 template<typename T>
class xyz
{
void foo()
{
if (T is a subclass of class bar)
do thi
我希望在模板類中有一個自定義方法 - 我將調用MyMethod - 只在Foo使用某些模板參數類型時調用Foo - ONLY (例如,當A是int且B是字符串時),否則,我不希望MyMethod存在於任何其他可能的Foo實例上。 這可能嗎? 例子: template<class A, class B>
class Foo
{
string MyMethod(whatever...);