C memset seems to not write to every member

后端 未结 7 2125
感动是毒
感动是毒 2021-01-18 09:01

I wrote a small coordinate class to handle both int and float coordinates.

template 
class vector2
{
public:
    vector2() { memset(this, 0, s         


        
7条回答
  •  无人及你
    2021-01-18 09:17

    The problem is this is a Pointer type, which is 4 bytes (on 32bit systems), and ints are 4 bytes (on 32bit systems). Try:

    sizeof(*this)
    

    Edit: Though I agree with others that initializer lists in the constructor are probably the correct solution here.

提交回复
热议问题