• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 869
  • Last Modified:

How do functions evaluate arguments?

I just want to know if I am on the right path.  The function will evaluate an argument like an error check?  Say for instance, if you are suppose to have numeric - it will evaluate the input whether it is numeric or alpha?  I am very confused with this.  I am just a beginner in C++, taking a class thorugh work and they did not have such good explainations on this subject enough for me to understand it.
0
Roni
Asked:
Roni
  • 4
  • 2
2 Solutions
 
AxterCommented:
The argument is evaluated at compile time, and if it does not match the function arugment type, or can not be converted via operators, than you'll get a compile error.
0
 
RoniAuthor Commented:
Can you give me an example?  I am still not understanding - so you are saying it does work like an error handler?
0
 
jkrCommented:
Basically, Axter is correct - however, just about the syntax. The is no logical evaluation, so you still could break functionality by passing nonsense values like e.g.

int Add(int a, int b) {

    return a + b;
}

Add((int) "one", (int) "two");

or

char arr[255] = "test";

strcat(test,(char*) 42);
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
AxterCommented:
>>so you are saying it does work like an error handler?

At compile time, yes.
But that's if you don't use explicit casting, as in jkr's example.

In general, you should avoid casting, because you're removing the compiler's ability to catch errors at compile time.
0
 
RoniAuthor Commented:
Thank you very much.  In reading your explainations and researching more, I now understand......thank you both again....
0
 
RoniAuthor Commented:
Okay....how do I change it?  
0
 
RoniAuthor Commented:
Thank you.....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now