Thread: Funny things happening outside of function

  1. #1
    Registered User
    Join Date
    Apr 2003

    Funny things happening outside of function

    Hi again all,
    This time i'm having trouble in returning a value from a class function. The function is supposed to work out the euclidian distance between two points i.e. sqrt( (x1-x2)squared + (y1-y2)squared). The distance i'm working out is over 10 points. When I was running the function in MSDOS it worked fine, however now that i'm tyring to run the program in MFC windows things aren't quite working.
    Here is the function for calculating the length:
    int CLine::SectionLength(int m_XYCoOrds[][2])
    	int TotalLength =15;
    	int SectionLength =0;
    	int Xvariance = 0;
    	int Yvariance = 0;
    	for(int i=0;i<8;i++)
    		variance = (m_XYCoOrds[i][0] - m_XYCoOrds[i+1][0]);
    		Yvariance = (m_XYCoOrds[i][1] - m_XYCoOrds[i+1][1]);
    		SectionLength = (sqrt( (Xvariance*Xvariance) + (Yvariance*Yvariance)));
    		TotalLength = TotalLength + SectionLength;
             return TotalLength;
    where m_XYCoOrds is a 2d array with i referring to the current point (0-9) and [i][0] being x, [i][1] being y.

    The TotalLength value returned is stored in the object under the name m_Length.

    When I try and see what the value is i call this in the View.cpp file
    CString test; //string to show the total length number
    int test3  =  pDoc->LineArray[0].m_Length;//get the first lines length
    test.Format(_T("test length is %d",test3));
    this has been producing the value -842150451
    I don't think its just a problem with the test.Format line as I can access other data members in the class that are initialised fine.
    As a quick test before wasting anyones time I set the function to just return the value 15, however m_Length was still showing -842150451. Can anyone tell me where this magic number has come from.
    Any help whatsoever is again greatly appreciated.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Where are you setting m_Length?
    Also, you still have TotalLength initialized to 15.

    Windows programming board <--- post windows code here.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post your games here...
    By Hammer in forum Game Programming
    Replies: 132
    Last Post: 02-28-2013, 09:29 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM