Results 1 to 5 of 5

Thread: Why? Invalid type argument of unary *

  1. #1
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Why? Invalid type argument of unary *

    K, I can't wrap my head around why this error keeps popping up. I am writing a conversion program and thanks to some prior help, I am able to start calculating some values, but I've run into a bit of a snag. Examples below:

    My defines:
    Qt Code:
    1. #define ACRE_SQ_CHAIN 10;
    2. #define ACRE_RODS 160;
    3. #define ACRE_SQ_LINKS 10000;
    4. #define ACRE_HECTARE 0.4047;
    To copy to clipboard, switch view to plain text mode 

    and the calculation routine - this works:
    Qt Code:
    1. if(to == "Hectare")
    2. {
    3. cvrt = temp * ACRE_HECTARE;
    4. answer.setNum(cvrt);
    5. leAcreAns->setText(answer);
    6. }
    To copy to clipboard, switch view to plain text mode 

    This doesn't work:
    Qt Code:
    1. if(to == "Rods")
    2. {
    3. cvrt = temp / ACRE_SQ_CHAIN * ACRE_RODS;
    4. answer.setNum(cvrt);
    5. leAcreAns->setText(answer);
    6. }
    To copy to clipboard, switch view to plain text mode 
    This is the section that is throwing the 'unary error'. If I change ACRE_RODS to the actual hard coded value, that is 160, error still occurs. Why is it that in some cases, it figures out I want to multiply the values, but in other cases, it thinks there is a unary * issue....

    If you look at the first section where it have temp * ACRE_HECTARE, that works fine, but, if I reverse it, so that it reads, ACRE_HECTARE * temp, it also throws the unary* error? What am I not seeing??

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Why? Invalid type argument of unary *

    remove the ';' from your defines.
    what you get is:
    Qt Code:
    1. cvrt = temp / 10; * 160;;
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    progman (21st March 2011)

  4. #3
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why? Invalid type argument of unary *

    Make a google search for "const instead Define". It is more than a matter of style

  5. The following user says thank you to Rhayader for this useful post:

    progman (21st March 2011)

  6. #4
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why? Invalid type argument of unary *

    Quote Originally Posted by high_flyer View Post
    remove the ';' from your defines.
    what you get is:
    Qt Code:
    1. cvrt = temp / 10; * 160;;
    To copy to clipboard, switch view to plain text mode 
    ** Smacks head against desk ** Thanks!

  7. #5
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why? Invalid type argument of unary *

    progman, thanks for the thanks but I think you should thank high_flyer instead

Similar Threads

  1. Replies: 7
    Last Post: 8th November 2012, 11:26
  2. Building static Qt. Error 126 invalid argument
    By kea_ in forum Installation and Deployment
    Replies: 2
    Last Post: 20th March 2011, 07:58
  3. GLib-WARNING **: poll(2) failed due to: Invalid argument.
    By December in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2009, 05:10
  4. Invalid return type
    By Salazaar in forum Newbie
    Replies: 3
    Last Post: 5th June 2007, 17:51
  5. invalid use of undefined type
    By mikro in forum Newbie
    Replies: 2
    Last Post: 9th April 2006, 12:10

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.