2
#include<vector>
struct TYPE {
    int a, b, g, d;
    bool bl;
};
int main() {
    std::vector<TYPE> i;
    std::vector<bool> b;

    TYPE* ii = &i[0]; // can work with int, double, char and something else
    bool* bb = &b[0]; // compile error
}

why only bool can't do it? I check TYPE can be int, double, char and user-defined-type.

sunkue
  • 278
  • 1
  • 9
  • 3
    As kmdreko pointed out, std::vector isn't actually a contiguous sequence of booleans in memory, it's a specialisation that uses 1 bit per bool – tomalbrc Oct 16 '20 at 06:24
  • 2
    See also here https://en.cppreference.com/w/cpp/container/vector_bool for more details. – Lukas-T Oct 16 '20 at 06:25
  • @kmdreko thx,vector is a bitset not an array of bools! I understand why It can't and how can I use this! thx a lot. – sunkue Oct 16 '20 at 06:29
  • @tomalbrc thx! I should remeber this vector is deferent with bool[]. – sunkue Oct 16 '20 at 06:31

0 Answers0