How do functions evaluate arguments?

Posted on 2006-03-23
Last Modified: 2009-07-29
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.
Question by:Roni
    LVL 30

    Accepted Solution

    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.

    Author Comment

    Can you give me an example?  I am still not understanding - so you are saying it does work like an error handler?
    LVL 86

    Assisted Solution

    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");


    char arr[255] = "test";

    strcat(test,(char*) 42);
    LVL 30

    Expert Comment

    >>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.

    Author Comment

    Thank you very much.  In reading your explainations and researching more, I now understand......thank you both again....

    Author Comment

    by:Roni do I change it?  

    Author Comment

    Thank you.....

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now