Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
But i am only thinking about holding data like coords or something, not some large amounts of sentences. Is there no kind of variable, like char (i tried lots of possibilities with that, but can't really get anywhere ...). What I want to do is a script that calculates distance between 2 points in coordinate system and I want specify which coordinates.
PHP Code:
//Models array should only have this kind of values: $models['object1']['x'] = 7831; $models['object2']['x'] = 1893;
function distance($objName1, $objName2){ x1 = models[$objName1]['x']; x2 = models[$objName2]['x']; //Function that actually does something }
//And than I simply put in the objects names in the arg field: distance("object1", "object2");
With of course y and z also.
But I believe you got the point ...
If vectors are the only solution, than I guess I'll go with it ...
Last edited by ArdentAngel; October 12th, 2012 at 12:33 AM.
Reason: Only merged to posts into one, to make it easier to track for everyone ...
Edit: Ah, but you can easily create your own structure to hold more coordinates.
Last edited by S_M_A; October 10th, 2012 at 02:42 PM.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Last edited by S_M_A; October 11th, 2012 at 02:28 AM.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Hi, I have a question. How could I create an array that would in PHP look like this:
PHP Code:
$something['argument1']['argument2'] = "some data to store";
I assume the underlying datastructure is a hash table. That's available in C++ as an unordered_map. In the newest compilers this will be available in the std namespace (header <unordered_map>), in older compilers it may be available in the std::tr1 namespace.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Thanks, that really helped. Now just to be clear: Why is in every function "return 0" command? (just to learn properly what you guys just pointed me out). I am a novice in C++. I thought it would be ... different ... I was able to get the hang of C# in period of 3 days, so I did not expected C++ to be that much different (specially from reading PHP books, because they always pointed out some other differences ...)
It's just because it shall be compilable if somebody copies the code. int distance(...) has to return something but as it is now it is incomplete.
The same goes for int main(). Sometimes you see people use void main and that's not ok according to the standard but accepted by most compilers. I think the reason for it is that in an embedded system there's nobody to return to so void main is quite common. If a watchdog isn't used, returning from main means that the unit has to be power cycled to be restarted.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
I thought it would be ... different ... I was able to get the hang of C# in period of 3 days, so I did not expected C++ to be that much different (specially from reading PHP books, because they always pointed out some other differences ...)
Don't expect to learn any significant amount of C++ in 3 days. In 3 months you could learn something useful, but it'll take years to become really proficient in C++. Which book are you using to learn?
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
I was able to get the hang of C# in period of 3 days, so I did not expected C++ to be that much different (specially from reading PHP books, because they always pointed out some other differences ...)
If you really expected to learn C++ in 3 days, you'll be very disappointed. Look at what was posted by myself, S_M_A, and others. Did you really expect to come up with those solutions with just 3 or so days of learning C++?
Don't expect to learn any significant amount of C++ in 3 days. In 3 months you could learn something useful, but it'll take years to become really proficient in C++. Which book are you using to learn?
No, but I did expect to discover by myself how to make the array look the way I asked here at the end.
I knew at the very beginning that C++ is advanced language. I never even said that I am a pro at PHP, I am only saying that I did not expect there to be that much of a difference, since with C# I got familiar with (as much as I could for what I had to write in it for a friend who had been learning this in school and none of his classmates knew how to do it. I was his last chance of making it happen (altough I am 3 years younger than he is) ... it wasn't that hard, I admit - I mostly had to get the hang of arrays, which took me 3 hours, since I am a self-learning programmer (if I can call my self that way), so I guess you know how that is ...) quite fast.
But now I see here is a way more than I first expected.
Right now for C++ I am using pure google only ... And what I find that way ...
So I am open for any book any of you might advise to be a good one.
Last edited by ArdentAngel; October 12th, 2012 at 08:30 AM.
Reason: Expanding it ...
No, but I did expect to discover by myself how to make the array look the way I asked here at the end.
I knew at the very beginning that C++ is advanced language. I never even said that I am a pro at PHP, I am only saying that I did not expect there to be that much of a difference, since with C# I got familiar with
There is a major difference in C++ and C#, one that may shock you. It is the major difference between C/C++ and most other language that's out there.
In C#, you make a mistake that violates memory in some way, you get a nice error at runtime saying you made a mistake. With C++, you are not guaranteed to get any such error message or warning when you make these mistakes. For example, access an array with an out-of-bounds subscript in C#, then do the same thing in C++. With C++, there is no guarantee that you get an "array subscript error" or similar message at runtime -- the program will run with that bug, and who knows what damage is being done.
The array subscript is just one out of many examples. You have heap management errors, buffer overwrites all caused by a myriad of different reasons, etc.
So you were learning all along "safe" languages (C#, PHP), where you can't make these types of errors without the system telling you that you made these errors. With C++, you're on your own if you make such errors. So you can code all sorts of crap with C++, the code will compile, and may even run, giving you the false sense that everything is OK when it isn't. Run the program on your customer's machine, and everything goes wrong.
To avoid such errors, write code so that it's safe and easily maintainable, etc. requires real experience, not a few days of tinkering around with C++.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; October 12th, 2012 at 11:53 AM.
Thank you all. The code worked perfectly (and I got the hang of it that far). But now I want to split it to multiple header and cpp files. However I keep getting :
error C2653: 'aa_physics' : is not a class or namespace name
error C3861: 'distance': identifier not found
Bookmarks