C++ is such a dumb fucking language. I just want a pointer to a method

C++ is such a dumb fucking language. I just want a pointer to a method.
What's a better language, Rust?

Attached: Untitled.png (979x515, 33K)

Other urls found in this thread:

isocpp.org/wiki/faq/pointers-to-members#addr-of-memfn
godbolt.org/z/3ZmsQp
godbolt.org/z/wdaeX2
ibm.com/support/knowledgecenter/en/ssw_ibm_i_74/rzarg/cplr034.htm
msrc-blog.microsoft.com/2019/07/18/we-need-a-safer-systems-programming-language/
twitter.com/SFWRedditVideos

for what purpose

you're retarded

Fuck off.
To learn this language.

&class_name::method

Also, read a book, nigger.

>C++ is a dumb fucking language
correct
>a better language, Rust
no
learn C and x86-64 and arm assembly.

No thanks, I don't like assembly or abstract assembly.
error C3867: 'bass::o_func': non-standard syntax; use '&' to create a pointer to member

jesus fucking christ, you might actually be too retarded for sepples
auto o_func_ptr = &bass::o_func;

now give up and go write python or whatever

>What's a better language, Rust?
you just answered your own question

It says the same thing you retard. It's a member function, not a static function. Hence the expression is semantically incorrect. The compiler gives a warning, too.

Javascript is made for subhumans like you.

>t. echoes from c++ septic hole

isocpp.org/wiki/faq/pointers-to-members#addr-of-memfn

noob

you cant have a pointer to a non-static member function

Damn

learn how member functions work
godbolt.org/z/3ZmsQp

>retard doesn't know how a language works
>f-fuck language
Typical Jow Forums.

>C++
C doesn't have this problem.

Oh fuck that I don't read assembly.

C++ requires intelligence to use.
go write in go, it was created for brainlets like you.

You don't deserve to program if your entire shtick is to be a living linter.

>intelligence
No it doesnt, it only requires knowledge. Not everyone doesnt want to read himself into a compiler , too nigger language

you don't need to read the assembly, just the syntax for using pointers to member functions.

works on my compiler:
godbolt.org/z/wdaeX2

Oh I see now, it's obvious. Wow C++ is nothing like C, I literally thought objects just have an extra function pointer to some imaginary function.
visual studio compiler complains it understood I meant the member method instead, and that I used the wrong syntax, which I did. Because :: are for namespace resolution, . is for member access. I'm trying to get the address of a member function, not a static one, so :: is incorrect semantically, though compilers patch it in as an edge case.

Okay guys so i have a code c++ question pls dont hate pls answer okay guys
so the compile program i using says that apparently it doesnt work? ?? i dont know what it means but heeres my code. thanks guys

cmd::hack("cia", 127, 0, 0, 1);
cmd::hack("nsa", 127, 0, 0, 2);
cmd::hack("fbi", 127, 0, 0, 3);
cmd::ddos(&yourip);


Yes i know the hacking is illegal but its the Jow Forums so people can do anything guys

>godbolt.org/z/3ZmsQp
why didn't you use a class like in the OP? are c++ devs allergic to clarity?

structs and classes are essentially the same

so fucking declare one, dumbass
that's not how you do it
you have to declare a member function pointer, assign it to the class, then invoke it on an instance of that class
the syntax is abominably retarded but there's no easy way to deal with the implicit this pointer

//the type of a member function with params
using mem_func = return_value (class_name::*)(params);
//a pointer to a specific member function
mem_func the_actual_invokable_pointer = &class_name::function;
class_name class_instance;
//this is how you actually call them, notice the .* syntax
((class_instance).*(the_actual_invokable_pointer))(params);

there is a fucking reason no one does this

>I just want a pointer to a method.
then do that? Fucking idiot
Learn C++

Why the fuck are you using C++ then? Fuck off retard.
Don't go to Rust either if you're not willing to learn assembly. Just fuck off back to Python.

He did, fucking idiot. Learn C++, retard.

>I don't like assembly or abstract assembly.
Then fuck off forever from all systems programming languages and never even touch them again in your entire life.

Pointers to non-static member functions are offsets from a pointer-to-member. They need to be different because a method must know what “this” for called method. This would be impossible with just a function pointer because C/C++ does not have first class functions.

You can use std::mem_fn but its use is discouraged. Better just wrap it inside a lambda.

we should be more friendly to newcomers or this will judt create a toxic environment.

haha retard

t. 7 years in industry, never wrote assembly in my entire life

OP is a faggot
&bass::s_func;
std::bind(b, &bass::s_func);

>I want a pointer
>Rust
???

Dude... Are you the Hacker known as 4(four) chan?

Attached: 1556318445547.jpg (323x241, 8K)

No, it will create an environment free from newcomers. It's great to eliminate retards.

>are c++ devs allergic to clarity?
from my experience, yes

Obviously auto doesn't work retard.
Then what, we run out of systems programmers? You dumbasses are having an overly tough time coming up with code or even verifying correctness for being the hotshots you sound like.

you're looking at it from the wrong perspective, what is clear to C++ developers is not clear to the unenlightened

They've gone too far down the rabbit hole and are incapable of explaining things in a way that a normal human can understand it

systems programming has _nothing_ to do with assembly. If you think it does, you're writing code wrong.

In java this is just
class Gay {
void myMethod (){
System.out.println("your gay lol");
}
public static void main (String[] args) {
Gay gay = new Gay;
void ptr = gay.myMethod;
}
}

>I just want a pointer to a method.
You don't. You want to call a method of an object from somewhere else. Calling a method without having an object makes no sense. Just use a lambda.

>{;}
What the fuck is this?
Disgusting

because it doesn't have the feature, to begin with.

>ITT: OP is retarded and doesn't know what are non static members

I am really curious to what OP is trying to do in his program.

>What's a better language, Rust?

Attached: rust.png (700x1007, 801K)

C++ dev here. You declare a pointer foo to a member function bar of class X.
int (X::*foo)(int, int) = &X::bar;
Then you dereference it in context of the object.
X x_obj = X();
(x_obj.*foo)(10, 20);

ibm.com/support/knowledgecenter/en/ssw_ibm_i_74/rzarg/cplr034.htm

>feature

Attached: costanza.jpg (243x197, 33K)

Yes, user, virtualization is a feature.

Is glowing in the dark also a feature, you CIA niggercattle?

>I can’t even into abstractions, it looks like alien magic to me
lol

I'm not implying you're an alien. I'm implying you're a nigger.

class bass {
public:
void o_func() {;}
};

int main() {
bass b;
void (bass::*o_func_ptr)() = &bass::o_func;

// Call the member function
(b.*(o_func_ptr))();

}


Welcome to the wonderful world of C++. We hope you enjoy the beautiful language we have produced.

JavaScript is not subhuman friendly, he will just try do 0.1 + 0.2 one day and will come here because of his extreme anger and confusion
>GRUG NOT KNOW DOUBLE POINT
>GRUG ANGERY

i know you are being ironic but that's actually a pretty amazing statement. The fact that you can create a function pointer by taking a reference to a class's member function, then dereference it on an object with its dot operator and actually call that objects function really shows the expressiveness of c++. Sure, it looks a bit ugly but that's just to make it work semantically.

Yes, I was ironic.
std::invoke is actually the new hotness which replaces the ugly call syntax.

Specifying the full type of the function pointer was obviously useless. You can just use auto or, if you truly need a way to get the function without the specific syntax, you could use a typedef and get the return value via decltype -
#include

class bass {
public:
void o_func() {;}
};

typedef decltype(&bass::o_func) BassFunctionPointer;

int main() {
bass b;
BassFunctionPointer o_func_ptr = &bass::o_func;

// Call the member function
std::invoke(o_func_ptr, b);
}

C++ is actually pretty awesome. Just sucks that it's absolutely not memory safe - smart pointers do help and so does std::span, but it's far from Rust.

>auto
kys

>Just sucks that it's absolutely not memory safe - smart pointers do help and so does std::span, but it's far from Rust.
not a real issue, stop shilling shitlangs

It isi absolutely a real issue. The massive amount of memory errors that plague all sorts of C(++) software even today is evidence of this.
Even Microsoft wants to use Rust now since they learned that C++ is simply not enough.

>source: dude trust me
this is a symptom of shit programmers more than anything else

>auto
just because you can doesn't mean you should

Source: msrc-blog.microsoft.com/2019/07/18/we-need-a-safer-systems-programming-language/

b-but Meyers-chan recommends use of auto in his book on modern C++

Meyers lives off writting books. He has to come up with new bullshit to fill the new books.
Auto is fucking cancer, makes you lose sight of what type a variable is. Interfaces are good for objects where you sometimes swap the implementations, not for primitive types.

Attached: 1544876617059.png (1223x368, 426K)

>be writing iterator loop
>std::vector::const_iterator pGrug = myGrugs.begin(); ...
>auto pGrug = myGrugs.begin();
damn i have no idea what this could possibly be

I feel bad for you seppletards. When will you have proper lambdas? std::for_each sucks.

>std::vector::const_iterator pGrug = myGrugs.begin(); ...

If this is what your code looks like without auto you probably shit in the street.

>What's a better language, Rust?
Rust butt fuckers can't use C++, blame the language when the compiler BTFO out of them. Many such cases.

ibm.com/support/knowledgecenter/en/ssw_ibm_i_74/rzarg/cplr034.htm

Read this you fucking homosexual.

Attached: D_kMnYOXoAAlhyG.jpg (493x700, 61K)

>Microsoft
>An authority on good code
>Even Microsoft wants to use Rust now since they learned that C++ is simply not enough.
Shove a coconut up your ass.

t. never worked on a codebase larger than his mom's basement

stop using microsoft's crap
either gcc or clang you total faggot

0.009 cents have been added to your GooglePlay® Account for this post.

It's more about knowing how to make optimized code, not literally sitting down and writing software in assembly.
>b-but I kn -
You're attitude towards assembly appears to indicate otherwise.

OP is trolling.

Output assembly is regularly inspected in any serious systems programming environments. Fuck off.

Dude a nonstatic member function on a non-instantiated class does not exist to be pointed to

>Then what, we run out of systems programmers?
We will never "run out" of programmers. Quality over quantity.

It's the other way around, C++ faggots can't use Rust, that's why they shit on it. You can tell because every time they whine about something trying to use it and blame the language, it turns out their code had UB in it (especially BC errors). If you think C++ is harder or hard in general you're pretty delusional, the only "hard" thing in it is template metaprogramming and not for any good reason.
Now for OP, they are retarded.

Attached: linked_cat_list.jpg (562x588, 173K)

>or this will judt create a toxic environment.
good

>Auto is fucking cancer, makes you lose sight of what type a variable is
if you lose sight of that then your design was terrible to begin with. you should be programming against interfaces not types anyway, the latter is brittle and doesn't support generic programming.

#include
#include

class MyClass {
public:
explicit MyClass(int x)
: x_(x)
{
}

void print_val()
{
std::cout

>What's a better language, Rust?
Yes, but it's also more complex/abstract. If you can't handle C++, you won't be able to use Rust.

>The massive amount of memory errors that plague all sorts of C(++) software even today is evidence of this.
uhh, no, those errors plague C software, not C++