const parameter problem
Oct 20, 2012 at 4:17pm UTC
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
if not, why? is there something like auto convert?
Oct 20, 2012 at 4:59pm UTC
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.
Oct 21, 2012 at 9:40am UTC
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.