error: default argument given for parameter 1,2 and 3 of'int volume

This code is giving error: Default argument given for parameter 1,2 and 3 of'int volume'.
what is the possible problem with the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 #include<iostream>
#include<iomanip>
using namespace std;
int volume(int L=1, int w=1,int h=1);
void funcone(int& x,double y=12.34,char z='b');
int main()
{
    int a=23;
    double b=48.78;
    char ch='M';
    cout<<fixed<<showpoint<<setprecision(2);
    cout<<"a="<<a<<" b="<<b<<" ch="<<ch<<endl;
    cout<<"volume="<<volume()<<endl;
    cout<<"volume="<<volume(5,4)<<endl;
    cout<<"volume="<<volume(34)<<endl;
    cout<<"volume="<<volume(6,4,5)<<endl;
    funcone(a);
    funcone(a,42.68);
    funcone(a,34.65,'Q');
    cout<<"a="<<a<<" b="<<b<<" ch="<<ch<<endl;
    return 0;
}
    int volume(int L=1,int w=1,int h=1)
    {
        return L*w*h;
    }
    void funcone(int& x, double y,char z)
    {
        x=2*x;
        cout<<"x="<<x<<" y="<<y<<" z="<<z<<endl;
    }
You can't re-declare default arguments twice in the same scope. In practice, this means that default arguments (usually) appear only at the first declaration of the function.

1
2
3
4
int volume(int l=1, int w=1,int h=1);
// ...
int volume(int l, int w, int h) 
{ return l * w * h; }


The details are here:
http://en.cppreference.com/w/cpp/language/default_arguments
Topic archived. No new replies allowed.