C++ call function with reference to array of const integers -
lets have these 2 function definitions:
int* first(int const (& array)[], int const size); void second(int const array[], int const size);
and @ implementation of second want make call first this:
void second(int const array[], int const size) { int* = first(*array, size); }
thats when compiler tells me: "no matching function call 'first'". correct way call first second in case?
if have use arrays, suggest using std::array
:
#include <array> template<size_t n> int first(std::array<int, n> const& array) ; template<size_t n> void second(std::array<int, n> const& array) { int = first(array); } int main() { std::array<int, 3> = {1,2,3}; second(a); }
if have array dynamic size, free burden of manually managing array , use std::vector
instead.
Comments
Post a Comment