- #1
Jamin2112
- 986
- 12
[C++] COMPILER ERROR: "error: expected ']' before ';' token"
I'm getting 3 errors on the line
denoted in my code.
error: expected ']' before ';' token
error: expected primary-expression before ']' token
error: expected ';' before ']' token
Can't figure out what's going on. Any help greatly appreciated.
I'm trying to make a dynamic bitset. My code is incomplete because I'm checking for errors as I write it and I'm stuck right now.
I'm getting 3 errors on the line
Code:
usi bA_indx_val = _booArr[indx/USI_BITS];
denoted in my code.
error: expected ']' before ';' token
error: expected primary-expression before ']' token
error: expected ';' before ']' token
Can't figure out what's going on. Any help greatly appreciated.
I'm trying to make a dynamic bitset. My code is incomplete because I'm checking for errors as I write it and I'm stuck right now.
Code:
#include <iostream>
#include <limits.h>
#include <assert.h>
typedef unsigned short int usi;
#define USI_BITS (sizeof(usi)*CHAR_BIT);
int main (int argc, char* const argv[]) {
return 0;
}class BitPack {
public:
BitPack(int);
~BitPack();
bool getVal(int);
int getSize();
void setVal(int, bool);
private:
usi* _booArr;
int _booArrLen;
int _numBoos;
usi _pow2(int);
};
BitPack::BitPack(int sz) {
assert (sz > 0);
_numBoos = sz;
_booArr = new usi[_numBoos/sizeof(usi)+(_numBoos % sizeof(usi) ? 1 : 0)];
_booArrLen = sizeof(_booArr)/sizeof(usi);
for (int i = 0; i < _booArrLen; ++i)
_booArr[i] = 0;
}
BitPack::~BitPack() {
delete[] _booArr;
}
bool BitPack::getVal(int indx) {
assert (indx > 0);
usi bA_indx_val = _booArr[indx/USI_BITS]; // ERROR
int rmndr_bits = bA_indx_val % USI_BITS;
for (int i = 0; i < rmndr_bits; ++i)
bA_indx_val /= 2;
return (bA_indx_val % 2 ? true : false);
}
int BitPack::getSize() {
return (_numBoos);
}
void BitPack::setVal(int indx, bool val) {
assert (indx > 0);
/*
I'm in the middle of writing this right now.
*/
}
usi BitPack::_pow2(int n) {
assert (n >= 0);
usi prdct = 1;
for (int i = 0; i < n; ++i)
prdct *= 2;
return prdct;
}