如何创建C ++中的字节数组? [英] How to create a byte array in C++?

查看:161
本文介绍了如何创建C ++中的字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看看在followng头文件

Please have a look at the followng header file

#pragma once

class MissileLauncher
{
public:
    MissileLauncher(void);

private:
    byte abc[3];
};

此产生的误差

Error   1   error C2143: syntax error : missing ';' before '*'  

我试图做这样

byte *abc;

,但它也失败了,同样的错误。然而,我发现我可以调用其他建于tyes阵列这样的例子,一个int数组。为什么这是发生在字节数组?如何解决此问题?我想在CPP文件中指定的值。任何想法?

but it also failed, same error. However, I noticed I can call other built in tyes arrays in this way for an example, an int array. Why this is happening to byte array? How to solve this? I would like to assign the values in cpp file. Any ideas?

推荐答案

尝试

class MissileLauncher
{
public:
    MissileLauncher(void);

private:
    unsigned char abc[3];
};

using byte = unsigned char;

class MissileLauncher
{
public:
    MissileLauncher(void);

private:
    byte abc[3];
};

**注:在旧的编译器(非C ++ 11)替换的typedef unsigned char型字节中的使用线;

**Note: In older compilers (non-C++11) replace the using line with typedef unsigned char byte;

这篇关于如何创建C ++中的字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆