const parameter problem

if i declare a funciotn like
1
2
3
4
 void func(const int a) {

...
}


when I use the function, do I need to specify variable const, like
1
2
const int x;
func(x);

if not, why? is there something like auto convert?
No you need not. For example

1
2
3
4
5
6
7
void func(const int a);

int main()
{
   int x = 10;
   func( x );
}


Moreover the following two function declarrations are equivalent and declare the same function

void func(const int a);
void func(int a);

So the following code is valid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

void func(int a);

int main()
{
   int x = 10;
   func( x );
}

void func(const int a)
{
   std::cout << "a = " << a << std::endl;
}



Here qualificator const means only that inside the body of the function you may not change parameter a that is a local variable of the function.
thanks a lot

qualificator const means only that inside the body of the function you may not change parameter a that is a local variable of the function.
Topic archived. No new replies allowed.