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
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
这么使用应该没问题的吧?
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
请使用类的成员函数来操作 Add GetAt InsertAt RemoveAt 函数
b.Add(0xbb);
b.Add(0xcc);
b.GetAt(0);
b.RemoveAll();
,还是报错, 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
基本都是这种,
会不会是头文件的问题? 注释掉这个声明后程序就没有问题了
error C2371: 'b' : redefinition; different basic types see declaration of 'b'
'b'重定义了,改一下
有的地方少了‘;’
CByteArray b;
b.Add(0xaa);
b.Add(0xbb);
b.Add(0xcc);
b.GetAt(0);
b.RemoveAll();要是不行我也没办法了。
Project Settings\c/c++\Code Generation中选择:
run-time library: Mulitithreaded
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);编译通过。可以的,可以试试