By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Visual C++ Error 2143

P: n/a
I'm getting a stranger error that I can't seem to figure out. I'm
using Visual C++ 6.0 and trying to compile the following code: (I've
pointed out the line that throws the "error C2143: syntax error :
missing ';' before '['")

#include <algorithm>
#include "frame.h"
#include "myio.h"

int Frame::read() {
int Lf; //Length of segment
int hv;

Lf=read2bytes();
P=readbyte();
y=read2bytes(); x=read2bytes();
nc=readbyte();

hmax=vmax=-1;
for (int i=0;i<nc;i++) {
c[i].id=readbyte();
idloc[c[i].id]=i;
hv=readbyte();
c[i].h=hv>>4; c[i].v=hv & 0xF;
if (c[i].h>hmax) hmax=c[i].h; if (c[i].v>vmax) vmax=c[i].v;
c[i].Tq=readbyte();
}

if (nError) return 0;
return 1;
}

void Frame::extenddata(int row) {
for (;ndatarow<row;ndatarow++) {
data[ndatarow]=new (int *) [nc]; //<--- This is the line with
the error!
for (int i=0;i<nc;i++)
data[ndatarow][i]=new int[x+40];
}
}

void Frame::cleardata() {
for (int i=0;i<ndatarow;i++) {
for (int j=0;j<nc;j++)
delete [] data[i][j];
delete [] data[i];
}
ndatarow=0;
}

Frame::~Frame() {
cleardata();
}

void Frame::write() {
write2bytes(0xFFC0); //SOF0 - Start of Frame 0: Baseline DCT
write2bytes(8+3*nc); //Length of marker segment
writebyte(P);
write2bytes(y); write2bytes(x);
writebyte(nc);
for (int i=0;i<nc;i++) {
writebyte(c[i].id);
writebyte((c[i].h<<4)|(c[i].v));
writebyte(c[i].Tq);
}
}

Anyone gots any ideas? I've totally stumped!
Thanks for your help,
--Ryan
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Ryan" <sc******@student.umass.edu> wrote...
I'm getting a stranger error that I can't seem to figure out. I'm
using Visual C++ 6.0 and trying to compile the following code: (I've
pointed out the line that throws the "error C2143: syntax error :
missing ';' before '['")
[...]
data[ndatarow]=new (int *) [nc]; //<--- This is the line with
Drop the parentheses.
the error!
[...]


Victor
Jul 22 '05 #2

P: n/a
Victor,
I'm getting a stranger error that I can't seem to figure out. I'm
using Visual C++ 6.0 and trying to compile the following code: (I've
pointed out the line that throws the "error C2143: syntax error :
missing ';' before '['")
[...]
data[ndatarow]=new (int *) [nc]; //<--- This is the line with the error

Drop the parentheses.

That didn't seem to work for me. I continued looking at this last
night and it seems that since nc is an int, that this line is trying
to cast the value of int nc to int *. Truth be told I'm not sure what
int * is, but I think it's a pointer. Is this true? If so, I don't
believe you can do this in C++, but rather more of a C operation. Am
I way off track here? If not, I'm still not sure how to fix it. Any
other suggestions?
Thanks all,
--Ryan
Jul 22 '05 #3

P: n/a
Ryan wrote:
That didn't seem to work for me. I continued looking at this last
night and it seems that since nc is an int, that this line is trying
to cast the value of int nc to int *. Truth be told I'm not sure what
int * is, but I think it's a pointer. Is this true? If so, I don't
believe you can do this in C++, but rather more of a C operation. Am
I way off track here? If not, I'm still not sure how to fix it. Any
other suggestions?


typedef int * pInt;
new pInt[nc];

VC++ has a bug with the "maximum munch" rules (or a similarly named rule).
The tokens following 'new' must be parsed for as long as the result could be
a type. But VC++ may have treated the () as argument delimiters.

VC++ is also supposed to do this properly:

SimCity & aCity (getSimCity());

But it won't.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #4

P: n/a
Ryan wrote:
I'm getting a stranger error that I can't seem to figure out. I'm
using Visual C++ 6.0 and trying to compile the following code: (I've
pointed out the line that throws the "error C2143: syntax error :
missing ';' before '['")
[...]
data[ndatarow]=new (int *) [nc]; //<--- This is the line with the error
I wrote
Drop the parentheses.



Ryan wrote then
That didn't seem to work for me.
WTF do you mean by "didn't seem to work"? Did it work or didn't it?
I continued looking at this last
night and it seems that since nc is an int, that this line is trying
to cast the value of int nc to int *.
No. It is a syntactically incorrect way of invoking "placement new".
Truth be told I'm not sure what
int * is, but I think it's a pointer. Is this true?
Yes, 'int*' is a pointer.
If so, I don't
believe you can do this in C++, but rather more of a C operation.
Huh?
Am
I way off track here? If not, I'm still not sure how to fix it. Any
other suggestions?


Since you didn't provide the definition of 'Frame' in your original
post, I assumed it has a data pointer called 'data', which is an array
of pointers to int or a pointer to a pointer to int. Is it?

Now, have you actually _tried_ removing the parentheses? With them the
statement looks a bit like a "placement new" but in fact is missing some
vital parts, besides, the expression in the parentheses must evaluate to
a real pointer. You, OTOH, have a type-id in the parentheses. That's not
acceptable.

Write your expression as

data[ndatarow] = new int*[nc];

and then read the chapter on dynamic memory allocation in your favourite
C++ book.

Victor
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.