1 sizeof 測量函數傳回值大小的時候,是不執行函數的
2 可變參數清單可以沒有一個參數,隻是不能用參數了(這句不知到對不對)
3 可變參數清單再模版執行個體化過程中比較弱;
#include <iostream>
using namespace std;
long long fun1(...)
{
cout << "in fun1 class" << endl;
return 3l;
}
class MyClass{
public:
typedef int x;
};
template <typename T>
char tmpfun1(typename T::x);
template <typename T>
long long tmpfun1(...);
#define has_member_of_X(T) (sizeof(tmpfun1<T>(0)) == 1)
int main()
{
fun1(1);
fun1("adfdf");
cout << "sizeof(fun1) = " << sizeof(fun1(2)) << endl;
if(has_member_of_X(int))
cout << "int has type member x" << endl;
else
cout << "int has not member x" << endl;
if(has_member_of_X(MyClass))
cout << "MyClass has type member x"<< endl;
else
cout << "MyClass has not type member x" << endl;
int i;
cin >> i;
}