- sizeof 在编译时,可以知道类大小
- 两个类比较之后,等到一个常数
- 用这个常数结合模板实现
#include<iostream>
using namespace std;
class A {
int a;
};
class B {
int a;
int b;
};
template<int c> struct Comp;
template<>
struct Comp<1> {
Comp() {
#pragma message("less")
}
};
Comp < sizeof(A) < sizeof(B) > comp;
int main()
{
return 0;
}