Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C function call operator

Name: Anonymous 2012-04-21 8:23

How do I define the function call operator of a user defined type in C? Every site I google says the following:

MyType operator()(int arg1,int arg2,int etc){
MyType x;
x.nigger=buttsecs(arg1);
x.mature=whatever(arg2);
return x;
}


...but my compiler thinks I'm defining the typecast operator and says I have an incorrect number of arguments.
What I am trying to do is be able to call a variable of MyType as if it was a function. I can accomplish the same thing by defining the [] operator (or some other operator) instead and use that to call, but the problem here is I'm trying to define some sort of a hybrid type that can even take function pointers as arguments and return function pointers, and it will not always be obvious to myself whether I'm calling it with a function or another type and I want the () operator to contain code that handles that shit automatically.

This sounds convoluted but in a nutshell: I want to overload the call operator () as if any other operator (like []) but my compiler is trying to overload the typecast operator instead. Obviously my syntax is incorrect and I haven't guessed the correct syntax yet, so correct me.

If this is a sepples only thing like I fear, I'm going to personally fucking find the guy who decided it would be a good idea to mutate a well defined programming language and spread it to the public like a flu that confuses and corrupts logic and syntax.

Name: Anonymous 2012-04-21 11:50

C doesn't have operator overloading, so you can't.
You can define functions however, which you can use the () operator on, if you so wish.

Name: Anonymous 2012-04-21 12:27

You can't overload any operators in C.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List