cannot convert parameter 1 from 'ArrayType [7]' to 'int []'
-
const int MIN_ELEMENTS = 5; typedef int ArrayType[MIN_ELEMENTS]; typedef int ElementType; bool findSum( ArrayType myArray, int n ) { ElementType firstFiveSum = 0; bool isSuccess = true; if( n < MIN_ELEMENTS ) { isSuccess = false; } else { for( int index = 0; MIN_ELEMENTS > index; ++index ) { if( !( myArray[index] < 0 ) ) { firstFiveSum += myArray[index]; } else { isSuccess = false; firstFiveSum = 0; break; } } } std::cout << firstFiveSum << "\n"; return isSuccess; } int main() { const int FIRST_ARRAY_SIZE = 7; const int SECOND_ARRAY_SIZE = 3; ArrayType myFirstArray[FIRST_ARRAY_SIZE] = {1,1,1,1,1,1,1}; ArrayType mySecondArray[SECOND_ARRAY_SIZE] = {1,1,1}; findSum( myFirstArray, FIRST_ARRAY_SIZE ); return 0; }
Visual Studio compiler gives an error like; cannot convert parameter 1 from 'ArrayType [7]' to 'int []' How can I solve this? Thanks in advance. - When in doubt, push a pawn! - -
const int MIN_ELEMENTS = 5; typedef int ArrayType[MIN_ELEMENTS]; typedef int ElementType; bool findSum( ArrayType myArray, int n ) { ElementType firstFiveSum = 0; bool isSuccess = true; if( n < MIN_ELEMENTS ) { isSuccess = false; } else { for( int index = 0; MIN_ELEMENTS > index; ++index ) { if( !( myArray[index] < 0 ) ) { firstFiveSum += myArray[index]; } else { isSuccess = false; firstFiveSum = 0; break; } } } std::cout << firstFiveSum << "\n"; return isSuccess; } int main() { const int FIRST_ARRAY_SIZE = 7; const int SECOND_ARRAY_SIZE = 3; ArrayType myFirstArray[FIRST_ARRAY_SIZE] = {1,1,1,1,1,1,1}; ArrayType mySecondArray[SECOND_ARRAY_SIZE] = {1,1,1}; findSum( myFirstArray, FIRST_ARRAY_SIZE ); return 0; }
Visual Studio compiler gives an error like; cannot convert parameter 1 from 'ArrayType [7]' to 'int []' How can I solve this? Thanks in advance. - When in doubt, push a pawn! -ArrayType
is a one-dimensional array with 5 elements. So when you writeArrayType myFirstArray[FIRST_ARRAY_SIZE]
that creates a two-dimensional array, which you can't pass to a function expecting a plainArrayType
. --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ | You Are Dumb