Thread: Use some quick help

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    8

    Question Use some quick help

    Hello again. I don't know what is wrong with the following equation, but I keep getting this error message.

    Error 4 error C2676: binary '-' : 'Vector' does not define this operator or a conversion to a type acceptable to the predefined operator

    Code:
    F*=G*((bodies[i].m*bodies[i++].m)/(sqrt((bodies[i].r.x-bodies[i++].r.x)*(bodies[i++].r.x-bodies[i].r.x)+(bodies[i++].r.y-bodies[i].r.y)*(bodies[i++].r.y-bodies[i].r.y))*sqrt((bodies[i++].r.x-bodies[i].r.x)*(bodies[i++].r.x-bodies[i].r.x)+(bodies[i++].r.y-bodies[i].r.y)*(bodies[i++].r.y-bodies[i].r.y))*sqrt((bodies[i++].r.x-bodies[i].r.x)*(bodies[i++].r.x-bodies[i].r.x)+(bodies[i++].r.y-bodies[i].r.y)*(bodies[i++].r.y-bodies[i].r.y))))*(bodies[i++].r-bodies[i].r);
    These are where the types come from

    Code:
    typedef struct {
    	double x;	
    	double y;	
    } Vector;
    
    typedef struct {
    	Vector r;			
    	Vector v;	
    	double m;	
    	char name[MAX_NAME];
    } Body;
    I'm lost as to what that error is from. Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    At the end of your statement:
    Code:
    bodies[i++].r-bodies[i].r);
    That needs to be an r.x-bodies or an r.y-bodies (I have no idea which).

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    8
    Thanks! I got it working!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm a bit concerned that the [i++] expressions are not guaranteed to be computed in the order you expect. I would recommend that you use a "[i+n]" where n is zero to however much you want it to be, and then do
    Code:
    i+=max_n;
    after the entire expression.

    Also, making it a bit less of a long line would help the understanding of the expression - remember, you or someone else may have to understand the entire expression at some later stage.

    Calculating complex expressions as partial components can also help the understanding some.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Yuck, what horribly long, wrong, and disgusting code.
    Break it down into much smaller parts.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  3. recursive quick sort - stack overflow
    By Micko in forum C Programming
    Replies: 9
    Last Post: 01-01-2005, 05:51 PM
  4. Questions on basic Quick Sort
    By Weng in forum C++ Programming
    Replies: 4
    Last Post: 12-16-2003, 10:06 AM
  5. Replies: 0
    Last Post: 04-30-2002, 07:24 PM