×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    73

    illegal constant expression

    Hi,
    I'm trying to compile QQrdecoder using Carbide and QT , but there are many compile errors
    illegal constant expression

    Code:
    	int* ITFReader::findGuardPattern(Ref<BitArray> row, int rowOffset, const int pattern[], int patternLen){
    			// TODO: This is very similar to implementation in UPCEANReader. Consider if they can be
    			// merged to a single method.
    			 int patternLength = patternLen;
    			int counters[patternLength];

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: illegal constant expression

    You're declaring the array "counters" with a size of "patternLength", which isn't a constant as required.

    Have you ever programmed in C before?

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    73

    Re: illegal constant expression

    I did define it as const and its still gives the same error , illegal constant expression

  4. #4
    Registered User
    Join Date
    Aug 2003
    Location
    Oulu, Finland
    Posts
    1,122

    Re: illegal constant expression

    A const variable is still a variable and not a compile-time constant. Stack-based allocation needs to know the space requirements at compile time. To allocate dynamically, use heap-based allocation such as operator new:
    Code:
    int *counters = new int[patternLength];

  5. #5
    Nokia Developer Champion
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: illegal constant expression

    Of course, then he needs to be sure to delete the counters object on exit. A better approach is to use a QArray<int>, unless performance is critical.

Similar Threads

  1. "illegal constant expression" in a static funtion
    By Cartouche67 in forum Open C/C++
    Replies: 1
    Last Post: 2009-09-14, 10:00
  2. illegal start of expression
    By razmyasdf in forum Mobile Java Games
    Replies: 2
    Last Post: 2008-07-28, 12:22
  3. Replies: 5
    Last Post: 2004-03-18, 07:45
  4. conditional expression of type 'class RArray<int>' is illegal ???
    By advocatee in forum Symbian User Interface
    Replies: 6
    Last Post: 2003-09-16, 10:02
  5. switch expression of type 'class TBuf8<3>' is illegal
    By Nokia_Archive in forum Symbian
    Replies: 1
    Last Post: 2002-05-31, 19:33

Posting Permissions

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