   trying to understand an example..
  Well I'm still at the very basics of learning C++ (haven't found any time the last 3 months to read more tutorials)...Yet I found a neat example I would really like to understand: it's an example of using vector maths to calculate elastic collisions between balls. - The maths and physics are no problem at all for me, however I would like to know how it is ACTUALLY implemented. SoI downloaded the source that came with the tutorial, and tried to compile it.... and failed: a lot of errors occured. download of the zipped source codeFirst I had a lot of problems of the type "cannot convert parameter 2 from 'char [100]' to 'LPCWSTR'" - Like I've been told earlier this is a problem with the difference between an ascii and unicode character set, and a quick solution would be to set the character set to "no set".After that the next 2 errors popped up:1>c:\..\bouncescope.cpp(129) : error C2065: 'M_PI' : undeclared identifier1>c:\..\bouncescope.cpp(427) : warning C4007: 'WinMain' : must be '__stdcall'M_PI isn't declared anywhere (I really wonder how the writer of this program could compile it) - But changing it to 3.1416 fixes the problem good enough.The other warning is "new" for me, but I think it's safe to ignore it for now? (it's a warning)trying to compile it once again results in a lot of warnings and 1 error:>..\..\bsrc.rc(48) : error RC2108 : expected numerical dialog constantwhere I found that it's probably on the line before:ICON IDI_MAINICON, IDC_PROGRAMICON, 12, 29 - I know adding random numbers is a bad idea: but this error was fixed by adding simply ",0 ,0" to the line.And then another error occured, something I didn't understand at all:Quote:1>bouncescope.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)What is this, how is it caused and how should I fix it?Besides that I looked at the source code (since that's why I downloaded the source) - Even though it's very good commented and easily to follow I got some questions related to it:In Vector2D.h this is a public function from the vector class:double x() const { return internalX; }What does that "const" mean here? - Actually I noticed all "get-type" function have this keyword, so it seems to be pretty important?removing it results into some errors:Quote:1>c:\...\vector2d.h(30) : error C2662: 'Vector2D::x' : cannot convert 'this' pointer from 'const Vector2D' to 'Vector2D &'Conversion loses qualifiersThanks in advance at answering my questions :).   
Quote:Original post by paul23And then another error occured, something I didn't understand at all:Quote:1>bouncescope.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)What is this, how is it caused and how should I fix it?This is what is called a link error. It's looking for the definition of a function called timeGetTime, but it's not defined anywhere. I would suggest removing all references to this in the sample if it's not needed. Otherwise, you need to include the right library that this function is defined in.Quote:Original post by paul23What does that "const" mean here? - Actually I noticed all "get-type" function have this keyword, so it seems to be pretty important?const is basically a way of saying that the variable cannot be changed. This stops data being accidentally overwritten. Try googling const correctness for a more detailed explanation.   ;Quote:Original post by paul23M_PI isn't declared anywhere (I really wonder how the writer of this program could compile it) - But changing it to 3.1416 fixes the problem good enough.The other warning is "new" for me, but I think it's safe to ignore it for now? (it's a warning)My assumption here is that whatever compiler math library the author used had M_PI defined and yours does not.  Defining it yourself is likely fine.The warning is because he has WinMain defined as an integer return, and if I remember correctly WinMain is typically defined as a int WINAPI return, which is likely why you're seeing the warning.  Shouldn't be a huge factor, either way, I would think.Quote:And then another error occured, something I didn't understand at all:1>bouncescope.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)What is this, how is it caused and how should I fix it?timeGetTime is a Microsoft function call to return the system time in milliseconds.  http://msdn.microsoft.com/en-us/library/ms713418.aspxWhat compiler are you using?  Perhaps your compiler uses a different function call to get the same data - if so, just change that function call to the proper one for your compiler.  Actually, since it's a linker error scratch that.  You may just need to link in the proper library file.  According to the link above, the file you need to link is Winmm.lib.Quote:In Vector2D.h this is a public function from the vector class:double x() const { return internalX; }What does that "const" mean here? - Actually I noticed all "get-type" function have this keyword, so it seems to be pretty important?What it does is essentially tell the compiler that it isn't going to modify any data in the object for which it is defined.  I believe it is usually more of an optimization thing than is required.  The reason you would get those errors is because it's called by the member function 'magnitude' which is also a constant function.  You can not call a non constant method from a constant method.  If you remove all the const keywords, it would work fine.  But it may not be as "optimized" at compilation.   ;  Thanks for the quick answer. However about the second thing:I know "const" makes a variable constant: however what does it do THERE..after a function?As far as I know a function is defined by:RETURNTYPE FUNCTIONNAME(ARGUMENTS){ CODE}while this uses:RETURNTYPE FUNCTIONNAME(ARGUMENTS) const{ CODE};  that tells the compiler that no variables in the object ur calling that function on will be changed. and a get would definitly fit that description.   