嗨,我对类/结构的大小有一些问题这是我的 Graphnode.h,我只有 4 个变量 - 一个 16 无符号字符数组,三个无符号字符,我认为大小应该是 19。为什么会这样32?
Graphnode currentNode;
cout<< sizeof(currentNode)<<endl;// why this is 32 ?
cout<< sizeof(currentNode.state)<< endl;// this is 16
图节点.h:
#include <stdio.h>
#include <stdlib.h>
#include <tr1/array>
//using namespace std;
class Graphnode {
public:
std::tr1::array<unsigned char, 16> state;
unsigned char x;
unsigned char depth;
unsigned char direction;
Graphnode(std::tr1::array<unsigned char, 16>,unsigned char,unsigned char, unsigned char);
Graphnode();
};
Graphnode::Graphnode()
{
int i=0;
for(i=0;i<16;i++)
{
state[i] = 0;
}
x = 0;
depth = 0;
direction = 0;
}
Graphnode::Graphnode(std::tr1::array<unsigned char, 16> _state,unsigned char _x,unsigned char _d,unsigned char _direction)
{
int i=0;
for(i=0;i<16;i++)
{
state[i] = _state[i];
}
x = _x;
depth = _d;
direction = _direction;
}