« first day (929 days earlier)      last day (2148 days later) » 

17:08
what's a good way to handle errors/exceptions in c++?
I see that most functions I'm using return -1 for errors
it would be very hard to do an if-statement every single time I call one of these functions
what's the proper way to handle these situations?
 
1 hour later…
nwp
nwp
18:13
@AfonsoMatos Throw an exception and don't handle it unless you can.
 
1 hour later…
19:31
Is doing float x = 3.5; int(x) same as static_cast<int>(x)?
Basically yes. Also when you wrote float x=3.5 you cast a double to a float. If you wanted the constant to be a float you could instead write 3.5f.
yes, thanks
what is the intanyway?
I mean the int(x)
is this calling a constructor?
nwp
nwp
It's a function-style C cast.
Same as (int)x.
20:09
oh ok
You might have wanted to do 'int a(25)'
	int new_x(pos.x);
	int new_y(pos.y);

	int new_x = static_cast<int>(pos.x);
	int new_y = static_cast<int>(pos.y);
which is better and why?
 
2 hours later…
22:08
Hey. I have a enum type thing in which I'm typing the same thing over and over. How can I make it shorter?
-----
static const string A = "ItemA"
static const string B = "ItemB"
static const string C = "ItemC"
......
-----
I'd like to something like #define IT = "static const string"

And then just list like this:
IT A = "ItemA"
IT B = "ItemB"
IT C = "ItemC"
nwp
nwp
Maybe you can make it an array.
Also this looks like a case for std::string_view instead.
I'm trying to do enum inheritance
https://stackoverflow.com/questions/644629/base-enum-class-inheritance
Basically, I've got some strings I'm passing around as ids, and I'd like to not be passing actual strings but instead something more enum like.
I mean, in the end, they're strings. But I want to make sure any spelling mistakes will be caught by the compiler.
nwp
nwp
You can use a real enum and index into an array of strings.
That's where the inheritance bit comes in. Say Parent has a few knobs it wants to register, it'll get they're id's from this enum.

But then child has some more knobs. It could create its own special enum, but then I'd slowly end up with many many different enums. I'd rather have the way it access it's knob ids be the same as its parent.
So if I make the "enum" into a class full of statics, I can extend it and have access to all parent knob "enums" and child knob "enums" from the same source. Should make for easier to read code.
------
Anyways, I remember there being a preprocessor way of basically doing "find and replace", but I have no idea what it's called. We used in college to make ASSERT turn into no code at all during production builds.
nwp
nwp
22:24
That is #define X Y.
@SephReed Okay, so the children should be named. So instead of doing parent->findWidget(close_button_enum)->doSomething() you should prefer parent->close_button->doSomething(). In Qt you automatically get this.

« first day (929 days earlier)      last day (2148 days later) »