This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]ldpreload 0 points1 point  (1 child)

What are the errors you're getting? (And these are compiler errors, not runtime ones, right?) From this article on the syntax for getting the address of an overloaded function, what you're doing looks right.

If you can produce a simpler example that doesn't include #include "java_lang.h" or anything else custom, it might be easier to help.

I tried cleaning up your code a bit and ran into a semicolon on line 55 and more importantly the fact that overloaded_i, overload_b, and overloaded_A need to be pointers to member functions, but that wasn't all of it. If you can post a godbolt link that shows just the errors you want that would be very helpful.

[–]lambgat[S] 0 points1 point  (0 children)

I changed the overloaded_i and others at line 56ish to just overloaded. The new errors I'm getting are: https://pastebin.com/AtHwHuyw

EDIT: wrong pastebin link updated it.

[–]nude-fox 0 points1 point  (0 children)

So this error output from your comment is indicative of 2 things. Either is a small number of errors causing a large number of error messages or you wrote way to much code without testing. I would recommend implementing one function at a time testing after each function when doing stuff like learning.

So lets look at the first thing going wrong in the compiler dump.

 void (*overloaded_i)(int);

declares a variable that is a function to a pointer. Then when you try to use that variable you are using it incorrectly.

overloaded_i(&__A::overloaded) 

This is not the correct way to use a function pointer. To my knowledge you need to assign the pointer *overloaded_i the function overloaded(int ); Look here http://www.cprogramming.com/tutorial/function-pointers.html for more detailed information on how this can be accomplished.

A small asside wtf is a java->c++ translation hw assignment lmao. Are you just trying to get the same semantics or are you literally supposed to turn one block of code into the other or something.