乱七八糟的片段

#include <iostream>

using namespace std;

class Unkown
{
public:
	void QueryInterface(int a)
	{
		cout<<"Hello, this your world!" <<endl;
	}
};

template <typename T> class Helper
{
public:
	T *t;

public:
	T *operator -> ()
	{
		cout<<"your world!" <<endl;
		return t;
	}
};

int main(int argc, char *argv[])
{
	Helper<Unkown> tt;
	tt->QueryInterface(10);

	return 0;
}
 
//函数模板
#include <iostream>

using namespace std;

template <typename T>

inline const T &Maximnum(const T &x, const T &y)
{
	if (y > x)
	{
		return y;
	}
	else
	{
		return x;
	}
}

int main(int argc, char *argv[])
{
	cout<<Maximnum<int>(3, 7) <<endl;
	cout<<Maximnum(3, 7) <<endl;
	cout<<Maximnum<double>(3.0, 7.0) <<endl;

	return 0;
}


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