测试代码:
#include <iostream> #include <typeinfo> template <typename T> void ref (T const& x) { std::cout <<"x in ref(T const&): " << typeid(x).name() << std::endl; } template <typename T> void nonref(T x) { std::cout << "x in nonref(T): " << typeid(x).name() << std::endl; } void func(char a[20], size_t b) { std::cout << b << " " << sizeof(a) << std::endl; } int main() { ref("hello"); nonref("hello"); char c[20] = "Hello World!"; func(c, sizeof(c)); return 0; }
结果:
时间: 2024-10-06 10:58:21