Results 1 to 6 of 6

Thread: declare array in a class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: declare array in a class

    If I declare it static is OK; but I'd like to do it not static:
    Quote Originally Posted by fullmetalcoder
    otherwise remove the "[]" in the initialisation.
    if I remove [] from initialization 'spec = {1,2,2,0};' , get an error:
    Qt Code:
    1. error C2059: syntax error : ']'
    2. error C2143: syntax error : missing ';' before '{'
    3. error C2143: syntax error : missing ';' before '}'
    To copy to clipboard, switch view to plain text mode 
    But is it possible to do this? Thanks
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    40
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: declare array in a class

    In the constructor you will have to declare each element of you array seperately.

    Qt Code:
    1. spec[0]=.4f;
    2. spec[1]=.4f;
    3. spec[2]=.4f;
    4. spec[3]=1;
    To copy to clipboard, switch view to plain text mode 

    of course you could employ a loop to make it easier.

    You might then want to develop a constructor that will receive the values in as four arguments.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: declare array in a class

    I hoped there was a way to don't inittialize array element serarately or with for.....
    Thanks
    Regards

Similar Threads

  1. Replies: 3
    Last Post: 27th December 2008, 19:34
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  4. Replies: 2
    Last Post: 16th March 2007, 09:04
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.