Thread: Help with default parameters

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Help with default parameters

    // Listing 5.7 - demonstrates use
    // of default parameter values

    #include <iostream>

    int AreaCube(int length, int width = 25, int height = 1);

    int main()
    {
    int length = 100;
    int width = 50;
    int height = 2;
    int area;

    area = AreaCube(length, width, height);
    std::cout << "First area equals: " << area << "\n";

    area = AreaCube(length, width);
    std::cout << "Second time area equals: " << area << "\n";

    area = AreaCube(length);
    std::cout << "Third time area equals: " << area << "\n";
    return 0;
    }

    int AreaCube(int length, int width, int height)
    {

    return (length * width * height);
    }

    // my question is this, why is it not
    //possible to pass height without passing in
    //a width?
    Last edited by incognito; 11-12-2001 at 07:39 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    As soon as you pass a parameter rather than relying on a default parameter, you've got to pass in parameters for everything to the left of it. So without changing the order of your parameters, what you asked isn't possible.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Utilizing another compiled program for a task.
    By kotoroshinoto in forum C Programming
    Replies: 6
    Last Post: 06-03-2008, 01:43 PM
  2. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  3. Help with default parameter value using ptr-to-functor
    By registering in forum C++ Programming
    Replies: 2
    Last Post: 03-24-2004, 04:21 PM
  4. Default Constructors w/Classes as Parameters
    By GrNxxDaY in forum C++ Programming
    Replies: 22
    Last Post: 07-31-2002, 07:50 AM
  5. Switching Default Buttons :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 07-02-2002, 04:08 PM