CByteArray cbyarr; 
cbyarr[0] = 0xaa;
cbyarr[1] = 0xbb;
cbyarr[2] = 0xcc;
cbyarr[3] = 0xdd;
 error C2466: cannot allocate an array of constant size 0
 error C2501: 'cbyarr' : missing storage-class or type specifiers
 error C2040: 'cbyarr' : 'int []' differs in levels of indirection from 'class CByteArray'
 error C2440: 'initializing' : cannot convert from 'const int' to 'int []'
        There are no conversions to array types, although there are conversions to references or pointers to arrays
 error C2501: 'cbyarr' : missing storage-class or type specifiers
 error C2040: 'cbyarr' : 'int [1]' differs in levels of indirection from 'class CByteArray'
 error C2440: 'initializing' : cannot convert from 'const int' to 'int [1]'
        There are no conversions to array types, although there are conversions to references or pointers to arrays
 error C2501: 'cbyarr' : missing storage-class or type specifiers
 error C2040: 'cbyarr' : 'int [2]' differs in levels of indirection from 'class CByteArray'
 error C2440: 'initializing' : cannot convert from 'const int' to 'int [2]'
        There are no conversions to array types, although there are conversions to references or pointers to arrays
 error C2501: 'cbyarr' : missing storage-class or type specifiers
error C2040: 'cbyarr' : 'int [3]' differs in levels of indirection from 'class CByteArray'
 error C2440: 'initializing' : cannot convert from 'const int' to 'int [3]'
        There are no conversions to array types, although there are conversions to references or pointers to arrays

解决方案 »

  1.   

    BYTE *pAry = new BYTE[5];我通常用这个,简单;
      

  2.   


    这么使用应该没问题的吧?
    BYTE *pByteArr = new BYTE[5];
    pByteArr[0] = 0xff;但是错误提示
    error C2466: cannot allocate an array of constant size 0
    error C2501: 'pByteArr' : missing storage-class or type specifiers
    error C2372: 'pByteArr' : redefinition; different types of indirection  
    see declaration of 'pByteArr'
    error C2440: 'initializing' : cannot convert from 'const int' to 'int []'
    There are no conversions to array types, although there are conversions to references or pointers to arrays
      

  3.   

    详看MSDN CByteArray 是个类 
    请使用类的成员函数来操作 Add GetAt InsertAt RemoveAt 函数
      

  4.   

    CByteArray b; b.Add(0xaa);
    b.Add(0xbb);
    b.Add(0xcc);
    b.GetAt(0);
    b.RemoveAll();
      

  5.   


    ,还是报错, error C2143: syntax error : missing ';' before '.'
    error C2501: 'b' : missing storage-class or type specifiers
    error C2371: 'b' : redefinition; different basic types see declaration of 'b'error C2143: syntax error : missing ';' before '.'
    error C2143: syntax error : missing ';' before '.'
    error C2501: 'b' : missing storage-class or type specifiers
    基本都是这种,
    会不会是头文件的问题?  注释掉这个声明后程序就没有问题了
      

  6.   

    加#include <afx.h>了吗?
      

  7.   

    #include "Afxcoll.h"
    error C2371: 'b' : redefinition; different basic types see declaration of 'b' 
    'b'重定义了,改一下
    有的地方少了‘;’
      

  8.   

    没道理啊,你的是MFC程序吗?我就算没有头文件也能编译通过,要不你随便弄一个函数就写这几句:
    CByteArray b; 
    b.Add(0xaa); 
    b.Add(0xbb); 
    b.Add(0xcc); 
    b.GetAt(0); 
    b.RemoveAll();要是不行我也没办法了。
      

  9.   

    删除Debug文件重新编译看看吧,有时有些问题真是很难找出来在哪。
      

  10.   

    运行时库选Mulitithreaded了吗?
    Project Settings\c/c++\Code Generation中选择: 
    run-time library: Mulitithreaded
      

  11.   

    不是吧,我在类文件中定义
    class CGUIDlg : public CDialog
    {
    CByteArray m_cyb;//定义数组。

    }
    然后在构造函数中赋值
             m_cyb.SetSize(10);//先制定大小,分配内存
    m_cyb.SetAt(0,0x01);//赋值,SetAt(索引,大小),从0开始
    m_cyb.SetAt(1,0x02);
    m_cyb.SetAt(2,0x03);
    m_cyb.SetAt(3,0x04);
    m_cyb.SetAt(4,0x05);
    m_cyb.SetAt(5,0x06);
    m_cyb.SetAt(6,0x07);
    m_cyb.SetAt(7,0x08);
    m_cyb.SetAt(8,0x09);
    m_cyb.SetAt(9,0x0a);编译通过。可以的,可以试试