编辑:我的问题的简短回答是,我对SFINAE可以做什么有错误的看法,而且根本没有检查函数体:sfinae是否实例化了一个函数体?
我有一个与此类似的问题:是否可以编写模板来检查函数的存在?
不同之处在于我不仅想检查函数是否存在,而且我还想知道它是否真的会通过SFINAE.这是我想要完成的一个例子:
struct A
{
void FuncA() { std::cout << "A::FuncA" << std::endl; }
};
struct B
{
void FuncA() { std::cout << "B::FuncA" << std::endl; }
void FuncB() { std::cout << "B::FuncB" << std::endl; }
};
template<typename T>
struct Inter
{
void FuncA() { t.FuncA(); }
void FuncB() { t.FuncB(); }
T t;
};
// Always takes some sort of Inter<T>.
template<typename InterType>
struct Final
{
void CallFuncs()
{
// if( t.FuncA() exists and can …Run Code Online (Sandbox Code Playgroud)