@sbi Just one last thought ;-) Microsoft's decision to pause the program at the end when starting via Ctrl+F5 is an arbitrary choice (there are other IDEs that don't have this behavior). What would you have your students do if there was no such artificial pause?
hmmm, I have a QWidget in which I draw a square, how can I make sure that the square doesn't go outside (becomes invisible) of the enclosing Widget, when moving the square around?
Again: That is not my case. Is it correct that you return multidimensional arrays by writing "Type**" and do you make the native arrays with new/delete?
C++ inherited arrays from C where they are used virtually everywhere. C++ provides abstractions that are easier to use and less error-prone (std::vector<T> since C++98 and std::array<T, n> since C++11), so the need for arrays does not arise quite as often as it does in C. However, whe...
@TonyTheLion Define a grid that has a fixed width and height. Then make sure your square's coordinates are always within the grid (this is where you need to perform bound checking when moving the square). Finally you need to define a function that can draw the entire grid. If the square never leaves the grid, then it will always be visible.
You can pass non-dynamic objects "into" scopes, but not "out of" scopes (Well, you can, but then you get a copy. Well, except if you return statics by reference.)
If your object needs to be created every time you enter a function, and that object needs to survive the function call, then you need a dynamic object.
@BPDeveloper if warrior has a destructor then you'll be in trouble unless you have correctly implemented the copy constructor and copy assignment operator.
What does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?
I stumbled upon the Stack Overflow question Memory leak with std::string when using std::list?. One of the first posters says:
Stop using new so much. I can't see
any reason you used new anywhere you
did. You can create objects by value
in C++ and it's one of the huge
advantages to us...
Most C++ books are not recommended. There are only a few good ones for beginners. "Accelerated C++" is what got me started and I recommend it to everyone wanting to learn the language.
Hey, it mentions unique_ptr! Albeit not sooner than page 648.
@BPDeveloper What is that, reference counting? We have std::shared_ptr<T> for that which does all the bookkeeping automatically without your intervention.
@BPDeveloper You don't even have to invoke release in C++ for reference counting to work. All you have to do is sit back and relax. Trust me, it really works. Just use std::shared_ptr<T> instead of T*, of course.
Thinking in terms of ownership and object lifetime are cornerstones of good C++ programming IMO. std::shared_ptr has the downside that it reduces your awareness of these.
I always used to think that if I were born a few hundred years ago my profession would have been to build clockwork. Seems to be the closest to programming.
Evening.
It would be hilarious to play this game as adults.
Typical example of weak typing is where 1 == "1" is not an error. However, a strongly language that supports operator overloading could provide an overload that enables this syntax. Does this (library feature) change a strongly typed language into a weakly typed language?
No, a weakly typed language does a coercion, that's why the comparison succeeds. Strongly typed language will not do any implicit conversions, whether there's overloaded operator or not.
Or something like that. All that theory is fuzzy and boring, anyway.
You are defining the distinction between weak and strong typing by the inner working of the program. I would compare them by (observable) behavior. If a strongly typed programming language can be made to behave exactly like a weakly typed programming language (through overload and stuff) then that would mean the distinction is kind of meaningless.
In this song the lyrics "fire in your eyes" really sound like "fire in your arse" to me. Listen at 0:14, 0:28 and especially at 0:51 (where she says: "I'm in your arse").
Now I have a big problem. I have no decent food at home (I mean, I have cookies and stuff like that, but not meat or rice or something). And it's too late to find a restaurant open.
I have a canvas, onto this canvas I draw 50x50 squares, lets say 2. I am able to move one with the arrow keypad. I do not want it to be able to move over the top of the other, so it has to hit the other squares edges and then stop. I'm using Qt
if (RectA.X1 < RectB.X2 && RectA.X2 > RectB.X1 &&
RectA.Y1 < RectB.Y2 && RectA.Y2 > RectB.Y1)
say you have Rect A, and Rect B.
Proof is by contradiction. Any one of four conditions guarantees that NO OVERLAP CAN EXIST.
Cond1. If A's left edge is to the...
I have a big class with lots of utility functions. those functions are very small and I would like them inlined.
The problem is they are all in a source file and should stay in the source file and not move to the header file (so I don't need to recompile everything every time one changes).
If I...
Zack, "because functions defined inside the class definition are not mandatory inline" - i guess it depends on the compiler, since I know at least one compiler where what I said is true. – suddnely_me 12 mins ago
even given a specific compiler, like Visual Studio, that has a __forceinline keyword, will still refuse to inline the assembler for some functions marked __forceinline