Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
たとえば、次のようなクラスがあります。
class Vector { float x, y, z }; Vector v;
そしてポインタ:
float *c = &v.x;
y および z メンバーへのアクセスにインクリメント演算子を使用すると、正しく機能しますか?
PS このやり方は悪いスタイルですが、それはスポーツの興味です。
いいえ。未定義の動作です。オブジェクト全体でポインター演算を実行することはできず、構造体のパディングを保証することはできません。
ただし、次のようなことができます。
class Vector { float v[3]; int& x() { return v[0]; } int x() const { return v[0]; } // and so on ... };