# assigning a member expression

## Recommended Posts

ok what i want to know is if there is a way to give a function a statement as a parameter for example (X>9) it will probibly have to take the form of a string but as long as i can convert it back in the end thats fine edit: or even to give it some kind varable or pointer would be fine too edit2: basicaly i want to know if there is a way to treat a compound expression as a single entity

What language?

##### Share on other sites
oops sorry [looksaround] C++

##### Share on other sites
Its fairly simple in scheme for example, but a bit more complex in C/C++/Java.

If you had to do it in C/C++ use the three dots and parse your input yourself, for example:

void complexExpresion(...){//look up va stuff to learn how to use the three dots	va_list ap;	va_start(ap, fmt);	va_end(ap);}

Anyway I copied this from a book for you:

statically typed language:
A language in which types are fixed at compile time. Most statically typed languages enforce this by requiring
you to declare all variables with their datatypes before using them. Java and C are statically typed languages.

dynamically typed language:
A language in which types are discovered at execution time; the opposite of statically typed. VBScript and
Python are dynamically typed, because they figure out what type a variable is when you first assign it a value.

strongly typed language:
A language in which types are always enforced. Java and Python are strongly typed. If you have an integer,
you can't treat it like a string without explicitly converting it.

weakly typed language:
A language in which types may be ignored; the opposite of strongly typed. VBScript is weakly typed. In
VBScript, you can concatenate the string '12' and the integer 3 to get the string '123', then treat that as
the integer 123, all without any explicit conversion.

##### Share on other sites
Probably the easiest way to do that is to use a function pointer. You can pass around pointers to functions just like any other pointer, though the syntax for declaring a function pointer type can be a bit messy. Here is an example I found in MSDN using qsort. You pass the function's pointer as an argument of a function by simply using the function's name without following it with parenthesis.

Function Declaration:

void qsort(
void *base,
size_t num,
size_t width,
//Function pointer parameter declaration:
int (__cdecl *compare )(const void *, const void *)
);

Example of Use:

int compare( const void *arg1, const void *arg2 );

void main( int argc, char **argv )
{
int i;
/* Eliminate argv[0] from sort: */
argv++;
argc--;

/* Sort remaining args using Quicksort algorithm: */
qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare ); /*see, the function 'compare' is being passed as an argument.*/

/* Output sorted list: */
for( i = 0; i < argc; ++i )
printf( "%s ", argv[i] );
printf( "\n" );
}

int compare( const void *arg1, const void *arg2 )
{
/* Compare all of both strings: */
return _stricmp( * ( char** ) arg1, * ( char** ) arg2 );
}

##### Share on other sites
all i get when surching for VA is people who live in vermont lol is there another name i could find it under?

##### Share on other sites
In what language? In many scripting languages, and dynamic programming languages, you have closures. In C or C++, you have to use various work-arounds to provide almost-closures, such as functor objects with overloaded function call operators or whatnot.

##### Share on other sites
Quote:
 Original post by raptorstrikeall i get when surching for VA is people who live in vermont lol is there another name i could find it under?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_va_arg.2c_.va_end.2c_.va_start.asp

##### Share on other sites
either what you guys are saying applys to me and im just not getting it or you missinterpret my question so ill state it one more time

is there a way to imput an equation into a function like:

solve(X > 1 - 2)
or to store it in a variable
expression_holder A = (X + 1 -2/2)
not what it equals because that will depend on the varable past at run time but just the equation thanks again [smile]

##### Share on other sites
There is no trivial way to do that in C/C++.

##### Share on other sites
dang! you think some one of thought of that by now thanks though (hmm NOW how am going to do this) [grin]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628314
• Total Posts
2982021

• 9
• 9
• 13
• 11
• 14