Function Paramater things...

1
2
3
4
type func_name(param)
{
code stuff
}


so for params I know you can have (modifier type var_name, modifier type var_name)

where modifier is something like out or ref... but what other modifiers are there?


const I believe is the only modifier, *int is actually a type, you are not declaring an int, you are declaring a pointer, it's a radically different type, you are not modifying type int, but rather the int is modifying what type of pointer you have.

I could be totally wrong on both points tho, I believe const is the only 'modifier', but I don't claim to know everything about the language.

edit:
1
2
volatile
abstract


edit2: http://msdn.microsoft.com/en-us/library/2e6a4at9%28v=vs.80%29.aspx
Last edited on
it would actually be int* not *int. And yeah there are other modifiers for types. const is definitely the most common though.
lol I am so bad at this.
Alright... not exactly what I meant... sorry... let me try this...

1
2
3
4
something function(out int h)
{
code
}

the out means that the variable you put in does not have to be initialized before it goes in, but will be before it comes out...

1
2
3
4
something function(ref int h)
{
code
}

the ref means that the variable you put in has to be initialize before it goes in but any changes made in the function to that variable is made is made in the scope above it...

what does it mean if I have:
1
2
3
4
something function(const int h)
{
code
}


and are there other modifier like that out there that i don't know about?
the out means that the variable you put in does not have to be initialized before it goes in, but will be before it comes out...
[snip]
the ref means that the variable you put in has to be initialize before it goes in but any changes made in the function to that variable is made is made in the scope above it...


Neither of these are true. 'out' and 'ref' have absolutely no significance at all and aren't even C++ keywords.

Some APIs #define them as macros so they can put it in function declarations to make the API easier to understand, but doing so is merely for your convenience and has no impact in the code.

Basically what I'm getting at, is those APIs are doing this:

1
2
3
4
5
6
7
8
#define out
#define ref

// note:  they're #defined as nothing

int func(out int h);
//  since 'out' is #defined as nothing, the above is the same as this:
int func(   int h);  // the compiler just erases the 'out' 


You could just as easily say int func(banana int h); if you choose to #define banana. But it really has no significance.

what does it mean if I have:
something function(const int h)


it means that 'h' is constant and cannot be modified in your code. IE: trying to do h = 5; would give you a compiler error because you're trying to modify a constant.

and are there other modifier like that out there that i don't know about?


Yes, volatile and restrict are two that I know of. Intrexa also linked to a page that listed several other keywords, some of which might also qualify (although many are MS specific keywords and not really C++ keywords)
thanks : )

and i am slightly embarrassed... out and ref are c# keywords...
Topic archived. No new replies allowed.