sizeof 可变参数的模版特化 C++ templa

1 sizeof 测量函数返回值大小的时候,是不执行函数的

2 可变参数列表可以没有一个参数,只是不能用参数了(这句不知到对不对)

3 可变参数列表再模版实例化过程中比较弱;





#include 

using namespace std;



long long fun1(...)
{
	cout << "in fun1 class" << endl;
	return 3l;
}

class MyClass{
public:
	typedef int x;
};



template 
char tmpfun1(typename T::x);

template 
long long tmpfun1(...);

#define has_member_of_X(T) (sizeof(tmpfun1(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;
}

sizeof 可变参数的模版特化 C++ templa_第1张图片


你可能感兴趣的:(C++)