作者LiloHuang (筑梦踏实)
看板Programming
标题Re: [问题] C++以函数传送阵列,而以指标方式接收
时间Sun Apr 15 14:19:19 2007
: 在不传递test的size进waha的情况下,
: 在waha里, 有办法算出tester这个array的大小吗?
: 谢谢
#include<iostream>
#include<cstdlib>
using namespace std;
template <typename T, size_t N>
void waha(T (&arr)[N]) {
for(size_t i = 0; i != N; ++i) {
cout << arr[i] << endl;
}
}
int main(void) {
string test[5] = { "ab", "bc", "cd", "de", "ef" };
waha(test);
system("PAUSE");
return 0;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.127.71.200