我不明白为什么在下面的代码中,我可以print_private_template
在编译器抱怨时创建函数print_private_class
:
#include <cstdio>
class A
{
private:
template <unsigned T>
struct B
{
};
struct C
{
};
public:
template <unsigned T>
B<T> getAb()
{
return B<T>();
}
C getAc()
{
return C();
}
};
template<unsigned T>
void print_private_template(const A::B<T> &ab)
{
printf("%d\n", T);
}
void print_private_class(const A::C &ac)
{
printf("something\n");
}
int main(int, char**)
{
A a;
print_private_template(a.getAb<42>());
print_private_class(a.getAc());
return 0;
}
这是预期的行为吗?编译器错误/扩展?
为了清楚起见,我的目标是使编译器在使用 print_private_template
和时出错print_private_class
。