C++ Logo

std-proposals

Advanced search

[std-proposals] operator alignof

From: Abdullah Qasim <iamminecraftredstoner_at_[hidden]>
Date: Sun, 1 May 2022 08:22:33 +0000
Consider:

class cstring {
  // assume public functions...

private:
  char* ptr; // used for dynamic allocation
  uint64_t length;
}

Now, assume I make cstring c(12)

Length takes 8 bytes.
Allocated char array takes 3 bytes.
Therefore:
  alignof(c)
returns 8

Why not 3?:

// In cstring
operator alignof () {
  return alignof (charArr);
}

Which is what the user expected!

Received on 2022-05-01 08:22:36