Using multiple default parameter values: defaults for reference parameters : default arguments « Function « C++ Tutorial

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C / ANSI-C
C Tutorial
C++
Visual C++ .NET
C++ Tutorial » Function » default arguments 
7.6.5.Using multiple default parameter values: defaults for reference parameters
#include <iostream>
#include <iomanip>
#include <string>
using std::cout;
using std::endl;
using std::string;

void show_data(const int data[]int count = 1,
            const string& title = "Data Values"int width = 10int perLine =5);

int main() {
  int data[] {1234};

  int dataItem = 99;
  show_data (&dataItem);

  dataItem = 13;
  show_data(&dataItem, 1"Unlucky for some!");

  show_data(data, sizeof data/sizeof data[0]);
  show_data(data, sizeof data/sizeof data[0]"title 1");
  show_data(data, sizeof data/sizeof data[0]"title 2"14);
  show_data(data, sizeof data/sizeof data[0]"title 3"144);

  return 0;
}

void show_data (const int data[]int count, const string& title,int width, int perLine) {
  cout << endl << title;                    
  cout << endl << perLine;
  cout << endl << width << data[2];    
  cout << endl;
}
Data Values
5
102

Unlucky for some!
5
102

Data Values
5
103

title 1
5
103

title 2
5
143

title 3
4
143
7.6.default arguments
7.6.1.Demonstrate default arguments
7.6.2.Function with two regular parameters and one parameter with default value
7.6.3.Use two default parameter values
7.6.4.Ambiguous function call with function with default parameter value
7.6.5.Using multiple default parameter values: defaults for reference parameters
7.6.6.demonstrates missing and default arguments
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.