C
Chameleon
#include <vector>
using namespace std;
struct Vector
{
double x,y,z;
double &operator[](int i) { return (&x); }
};
void here_it_comes(const vector<Vector> &vertex)
{
double a = vertex[0][0]; // compile error
double b = const_cast<Vector&>(vertex[0])[0]; // no problem, but why
the need not to be const? I change it nowhere.
}
int main() { return 0; };
/*
1.cpp: In function 'void here_it_comes(const std::vector<Vector,
std::allocator<Vector> >&)':
1.cpp:14: error: passing 'const Vector' as 'this' argument of 'double&
Vector:perator[](int)' discards qualifiers
*/
using namespace std;
struct Vector
{
double x,y,z;
double &operator[](int i) { return (&x); }
};
void here_it_comes(const vector<Vector> &vertex)
{
double a = vertex[0][0]; // compile error
double b = const_cast<Vector&>(vertex[0])[0]; // no problem, but why
the need not to be const? I change it nowhere.
}
int main() { return 0; };
/*
1.cpp: In function 'void here_it_comes(const std::vector<Vector,
std::allocator<Vector> >&)':
1.cpp:14: error: passing 'const Vector' as 'this' argument of 'double&
Vector:perator[](int)' discards qualifiers
*/