Results 1 to 8 of 8

Thread: Array declaration problem

  1. #1

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362

    Array declaration problem

    Code:
    const usi iSize= SizeOfMyFile(File);
    
    char sFile[iSize];
    Error :

    1-Expected constant expression
    2-cannot allocate an array of constant size 0
    3-unknows size

  2. #2
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    In visual basic you cant declare Consts with arguments
    cause it has no preprocessor.

    Is that still true in C++?

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Evan is right. You have to use some immediate value that the compiler can resolve. Not something that arises only during run-time.

  4. #4

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    I hate that grrr

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You have to use new if you want to have an array of dynamic or runtime-determined size.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Tell me if that good :
    Code:
    const usi iSize= SizeOfMyFile(File);
    
    char sFile = new char[iSize];

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    if the first line is inside a function it's ok, else remove the const.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    ok thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width