fill pointer array?
-
Hallo,
ich möchte ein Pointer Array: T* foo[5]; mit NULL füllen.
Probiert habe ich das so:
fill(foo, foo+5, NULL);
aber dann meckert mein Compiler immer:Error 22 error C2440: '=' : cannot convert from 'const int' to 'T *' d:\microsoft visual studio 8\vc\include\xutility 2949
Weiß wer wie das geht?
-
memset(foo, sizeof(foo), 0); ?
fill(foo, foo+5, (T*)0); ?
-
Fellhuhns Varianten (memset muss nicht funktionieren und passt logisch nicht), oder
fill_n(foo,sizeof foo/sizeof *foo, (T*)0);template<typename T> struct identity { typedef T type; }; template<typename T, std::size_t N> void fill_array(T (&arr)[N], const typename identity<T>::type& value = T()) { std::fill_n( arr, N, value ); } ... T* foo[5]; fill_array(foo); fill_array(foo,0);bei der Definition automatischer oder statischer Variablen:
T* foo[5] = {};
bei nichtstatischem Member foo: in der ctor-Initialisierungsliste
: foo()
bei new[]:
new T*[5]()...
...new(&foo) T*[5]()
-
Frage hat sich erledigt!!!! Danke!!!!!