サイズ不明の配列へのポインタを引数に取る関数:定義編。
http://d.hatena.ne.jp/sulpsulpc/20061125では宣言する方法のみだったので、今回は定義する方法。
#includetemplate struct P { typedef R func(A*); }; P >::func foo; template struct I { friend R foo(A* x) { X y= *x; std::cout << y[0] << y[1] << y[2] << std::endl; } }; extern int a; template struct I , int*>; int main() { foo(&a); } int a = {1,2,3};
クラステンプレートのフレンド関数定義を利用して定義する。
この方法は、GCC version 4.2以降でのみ利用できる。
それ以前のversionでは、Internal compiler errorになる。
regressionではないので、修正されないだろうから、報告はしない。