Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. cannot convert parameter 1 from 'ArrayType [7]' to 'int []'

cannot convert parameter 1 from 'ArrayType [7]' to 'int []'

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpdatabasevisual-studiohelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sacoskun
    wrote on last edited by
    #1

    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! -

    M 1 Reply Last reply
    0
    • S sacoskun

      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! -

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      ArrayType is a one-dimensional array with 5 elements. So when you write ArrayType myFirstArray[FIRST_ARRAY_SIZE] that creates a two-dimensional array, which you can't pass to a function expecting a plain ArrayType. --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ | You Are Dumb

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups