209
Deltarule (lemmy.world)
you are viewing a single comment's thread
view the rest of the comments
[-] programmer_belch@lemmy.dbzer0.com 8 points 1 month ago

I didn't need to do this but I did and now I want it in my comment history:

class Suckable {
    bool unsucked;

public:
    Suckable () {
        unsucked = true;
    }

    void Suck() {
        unsucked = false;
    }

    void CheckAndSuck() {
        if (unsucked) {
            Suck();
        }
    }
};

Sorry for making you see c++, it's the language I'm currently using. This program compiles on my machine and doesn't use global variables.

[-] davidagain@lemmy.world 3 points 1 month ago* (last edited 1 month ago)

Indeed, indeed.

No need to apologise for posting c++ in the channel. The programming world owes a lot to Prof. Stroustrup. I enjoyed your reply a great deal.

You have two choices: firstly, a regular regular attribute, where you can Suckable myThing; and myThing.CheckAndSuck; etc to your heart's content, and indeed no global variables are being sucked.

But you can also declare static bool unsucked; and what is a class variable if not a global variable by another name?

In fact, what is to stop your innocent-sounding accessor method from nuking the filesystem or calling memLeak.recurse();?

I'm not sure that these things keep you up at night, but you have my sympathy if they do.

If there was anything I could do to help you relax after a stressful day of multiple inheritance and manual memory management, I would.

Well, except that of course. I mean, we all draw the line somewhere.

Unless we've had too much to drink or smoked too much weed, in which case boundaries seem less important at the time.

One time in college, my friend....

but no, that's another story for another thread.

[-] programmer_belch@lemmy.dbzer0.com 3 points 1 month ago

ASMR: talking about pros and cons of c++ with your college friend

[-] davidagain@lemmy.world 3 points 1 month ago

Now my spine is all tingly and I don't know what it means. I'm having some really weird feelings right now.

this post was submitted on 02 Oct 2024
209 points (98.2% liked)

196

16494 readers
2765 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 1 year ago
MODERATORS