S
sumsin
Why the below two code snippet behave differently
Case 1:
#include <iostream>
void foo(const int *i)
{
int *local = i;
}
int main(void)
{
return 0;
}
and Case 2:
#include <iostream>
void foo(const int i)
{
int local = i;
}
int main(void)
{
return 0;
}
compilation command
g++ -Wall test03.cpp -o test03
In case 1 I got the below error.
error: invalid conversion from `const int*' to `int*'
In my understanding for an assignment:
- first the lvalue are rvalue must be of compatible type without
considering the qualifiers.
- then the lvalue must have all or more qualifiers than rvalue.
So its ok that I getting an error for case 1 but why its not happening
in case 2.
please clarify...
Case 1:
#include <iostream>
void foo(const int *i)
{
int *local = i;
}
int main(void)
{
return 0;
}
and Case 2:
#include <iostream>
void foo(const int i)
{
int local = i;
}
int main(void)
{
return 0;
}
compilation command
g++ -Wall test03.cpp -o test03
In case 1 I got the below error.
error: invalid conversion from `const int*' to `int*'
In my understanding for an assignment:
- first the lvalue are rvalue must be of compatible type without
considering the qualifiers.
- then the lvalue must have all or more qualifiers than rvalue.
So its ok that I getting an error for case 1 but why its not happening
in case 2.
please clarify...