[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/jp/ - Otaku Culture


View post   

File: 11 KB, 350x460, chair3.jpg [View same] [iqdb] [saucenao] [google]
483397 No.483397 [Reply] [Original]

#include "shiki.h"

void Shiki::seeAChair(Chair* chair) const
{
try{
throw chair;
}
catch(Chair* chair){
delete chair;
while(true){
cout << "THIS CHAIR ";
}
}
}

>> No.483403

no exit condition on that loop?

>> No.483413

>>483403
no

>> No.483417

Have you read your SICP today?

>> No.483432
File: 80 KB, 421x504, 1208715000441.jpg [View same] [iqdb] [saucenao] [google]
483432

>>483417
Yes
>>483403
No. THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR THIS CHAIR

>> No.483449
File: 41 KB, 250x714, 1208715270687.jpg [View same] [iqdb] [saucenao] [google]
483449

>> No.483462

>>483397
Wait.

Wait wait wait.

I know I'm rusty on my try/catch error handling, but... throw? Some sort of "return error if the variable is there" thing?

Also, you lost me on using the const after the the method call.

>> No.483486

>>483462
Also, there's try/catch error handling in C++?

>> No.483492

>>483486
yes, but it's not native to c++

>>483462
throw is the command you use to trigger the error. if something bad happens, throw an exception and gtfo of that block of code

>> No.483495

>>483486
facepalm.jpg

>> No.483512

>>483495
I am rather ⑨.

>>483492
...I knew that about throw, for some reason. It just slipped my mind, I guess.

I need to get off my ass and actually read SICP.

>> No.483517

>>483462
const because the method doesn't modify the Shiki object.

>>483486
>Also, there's try/catch error handling in C++?
facepalmHiRes.tif

>> No.483579

>>483517
>const because the method doesn't modify the Shiki object.

The method isn't actually modifying anything in the object as far as I can see. Is this just a good programming habit to include it or something?

>> No.483625

>>483579
Yes, it's called const-correctness. A const function can only call other functions that don't modify the object, so your (type) safety is guaranteed.

>> No.483640

>>483625
Huh.

Most of my experience is with C#, where I don't think I've ever encountered that. I know (or at least I think I do) about scope, and that seems like the same thing as const-correctness, just... automatic.

Am I right, or am I way off the point?

>> No.483664

>>483640
C# does not support const-correctness (and it's been criticized for it).
const is just a safety for the code and an optimization hint for the compiler. Say you use a function to search through a container inside a const method, but you want the container to stay in the same order as it was. If the search function modifies the container's order, it won't be a const function, so the compiler will whine because you're using a non-const function in a const method. So it's an extra safety. You can also use it to make sure nothing in your code will write on a read-only file, etc.

>> No.483713

>>483664
Ahhh, I get it now, thanks.

As an expression of my gratitude, feel free to rub my erect, manly nipples.

>> No.484082
File: 79 KB, 410x430, 1208723706738.jpg [View same] [iqdb] [saucenao] [google]
484082

>>483713

>>
Name
E-mail
Subject
Comment
Action