The following code compiles with g ++ v4.8.1 and outputs 45, but is its compilation guaranteed based on the standard? Will other compilers complain?
#include <iostream>
#include <vector>
void test(const std::vector<int>& a, std::vector<int>& b) {
b[0] = 45;
}
int main() {
std::vector<int> v(1,0);
test(v, v);
std::cout << v[0] << std::endl;
}
I understand that there is nothing wrong with the definition of a function, but when calling testwith the same object, vI was somewhat expecting a warning that I was passing one object as a const- const.
source
share