<分区>
1) 我有两个类(class) class A
和 class B
两者都有一个名为 foo
的方法但具有不同的参数列表。
class A {
public:
void foo(int a);
};
class B {
public:
void foo(int a, int b);
};
2) 此外,我有一个 class C
使用模板参数 T
还有一个 foo
方法如下
template <typename T>
class C {
public:
void foo();
private:
T t_;
int a_;
int b_;
};
3) 我想同时使用 class A
和 class B
作为 class C
的模板参数.
说我想要一个方法 C::foo
实现如下:
template <typename T>
void C<T>::foo()
{
if (compile time check: T has foo(int a, int b))
t_.foo(a_, b_);
else
t_.foo(a_);
}
如何表达 if
上面的声明 C++11
?