Newbie question about functions

Hi i'm new here and i'm really not familiar much with proper terminology since I originally studied C++ in Finnish.. So bear with me..



int Val (Var)
{
return int(Var);
}

how can I express Var so that it can be either a int value or a pointer to a int value?

Comments

  • [code]int val (int var)
    {
    return var;
    }[/code]

  • Do you mean function overloading?

    In that case, add this to Lundin's code:
    [code]
    int val (int* var)
    {
    return *var;
    }
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • I am not sure if I understood the question and the responses correctly. However, from what I have understood (of the question that is)

    union choose
    {
    int a;
    int* b;
    }Val;

    int Var(union Val)
    { //do what you want to do with it}

    However, this is still incomplete. There is no way to figure out whether the value in the union is a pointer or an integer value.
    :
    : Do you mean function overloading?
    :
    : In that case, add this to Lundin's code:
    : [code]:
    : int val (int* var)
    : {
    : return *var;
    : }
    : [/code]:
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry

    Programming is a race between software engineers striving to build bigger and better idiot-proof programs,and the Universe trying to produce bigger and better idiots. So far,the Universe is winning.
  • : I am not sure if I understood the question and the responses
    : correctly. However, from what I have understood (of the question
    : that is)
    :
    : union choose
    : {
    : int a;
    : int* b;
    : }Val;
    :
    : int Var(union Val)
    : { //do what you want to do with it}
    :
    : However, this is still incomplete. There is no way to figure out
    : whether the value in the union is a pointer or an integer value.

    Hence, the C++ solution of function overloading: both an 'int' and an 'int*'.
    Ofcourse, we're all still speculating until the OP says if we're on the right track or not.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • I'm not sure what function overloading is, but the idea was so that the function int Val() is prepared to do calculations whether Var is a pointer or type int.
  • ah yea, I checked some online resources and FUNCTION OVERLOADING was indeed what my question was about.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories