为什么const pA这A *const是我希望看到的const A*?
typedef struct {
uint32_t i[4];
} A, *pA;
class B {
public:
uint64_t i[2];
};
void f(pA aa) {
std::cout << std::hex << aa->i[0] << " "
<< aa->i[1] << " "
<< aa->i[2] << " "
<< aa->i[3] << std::endl;
}
void ff(const std::vector<B> &v) {
f(const_cast<pA>(reinterpret_cast<const A *>(v.data())));
// f(const_cast<pA>(reinterpret_cast<const pA>(v.data())));
}
int main() {
std::vector<B> vB;
vB.push_back({1, 1});
ff(vB);
return 0;
}
好吧,自己判断 - 它是什么
pA?这是一个指向A.那是什么
const pA?这是一个常数pA,即 指向 的常量指针A,而不是指向常量的指针A。合乎逻辑吗?const指一切pA作为一个整体 - 即 这是A* const- 一个指向A, 常量 ...