C++ is so confusing

C++ is so confusing
Can someone explain this code
#include
#include

struct Foo {
Foo() { std::cout

Attached: 1424539769227.png (3000x3000, 314K)

give up already

P-pls respond

>So for example why does function
> void operator()(Foo* p)
>
>have 2 times () () and then const at the end?

Because this is a function operator. You are using a class as if it were a function. The benefit of doing this is that you can benefit from class constructs like destructors to guarantee memory safety.

>When smart pointers sh4 and sh5 initalized wtf is the second argument after "new Foo"

It's a user-defined function which is called to free/delete Foo. 99.99% of the time you will not need it.

>tfw just learning about pimpl idiom
I understand the point of it, but there's no way I'd be able to implement it. So much bloody stuff to learn.

I just had online exam for a job (junior position) and it was filled with crap like this.

Hiring processes for software developers are notoriously bad across the industry. The best thing you can do is just practice implementing data structures and hope that the company isn't dumb enough to try and quiz you on specific APIs.

Reading about that kind of shit above all else drove me away from using C++ in my free time. Doing retarded gymnastics like that just to fudge around the stupid C header file system they've failed to replace in the last three published standards is just insufferable.

I'm still learning, but the reason you see the Foo() and ~Foo() there is because those are the constructor and destructors for the class.

The reason that function has two () is because *I THINK* they are overloading the () operator. In fact, you can do this with any operator in C++. I don't remember what the const is for tho, sorry. Someone please correct me, I want to know if my dollars are being put to good use.

>The reason that function has two () is because *I THINK* they are overloading the () operator. In fact, you can do this with any operator in C++. I don't remember what the const is for tho, sorry. Someone please correct me, I want to know if my dollars are being put to good use.

operator() allows the object to be called as a function, the const modifier specifies that operator() will not change any non-mutable state in the object, and means that it can be called on a const object

>When smart pointers sh4 and sh5 initalized wtf is the second argument after "new Foo"
By default a shared_ptr just uses std::default_delete which obviously just calls delete when the use count hits zero.
[](auto p) {
std::cout

If you're going to use C APIs like that, it's easier to wrap them up in a class and give them the correct semantics and constructors/destructors.

That should make it completely compatible with the STL without having to add any additional wrappers. And of course it can also be tested in isolation.

In regard to pic related, please tell me this is bait or a meme

>that pic
couldn't you just say }else{ y = false;}

>If you're going to use C APIs like that, it's easier to wrap them up in a class and give them the correct semantics and constructors/destructors.
Didn't say it was the proper way, just what I've seen it used for.

You could also just do
y=x

nice bait

Fair enough, seeing things like that just trigger my autism. Casually mixing C with C++ generally ends badly.

operator()() is just an operator overloading,struct Foo is just a class with a consructor and a destructor and the whole purpose of the program seems to be an example program on how to use smart pointers (shared_ptr).

Yes, I am learning smart pointers / shared_ptr but C++ has very confusing syntax, specially with newer versions c++14 / 17