[SOLVED]"new" operator compile error

Hi all, I hope you can help me with this:

when using the 'new' operator in this line:

char *numbuffer = new char[len+1]

(with len being defined, no worries there), I get the 'undeclared identifier' compile error:

'new' undeclared (first use in this function)

Somehow, this scares me, since I think I used the operator correctly.

Edit: I hate how Google gives me no results before writing posts here and how it brings me exactly what I needed after I've posted the post.

I just used malloc and free instead:

1
2
char *numbuffer;
numbuffer = (char*) malloc(len+1);    //len is defined beforehand 


and in the function that calls the one which contains the snippet above:

1
2
3
char *strTrainno = getTrainno(buffer);     //getTrainno is the name of the function mentioned above, buffer a parameter passed to the current fn
//do stuff with strTrainno
free(&strTrainno);
Last edited on
Just out of interest have you thought about why new didn't work or gave that error??
I guess I forgot to #include <new> .
Last edited on
Just out of curiosity, which compiler are you using? I have only ever seen a problem like that when someone tried to compile C++ with a C compiler.
Dev C++ 4.9.9.2's standard compiler (first time working with this IDE, previous C++ coding has been done in Apple's XCode 2.x, on PPC macs), which, according to Dev C++'s offline help, is MingW32.

I have another question, though. What does one do when s/he is the only one coding and there is literally noone nearby (physically) to ask to look at the code? Because I don't want to litter any forum with requests which basically boil down to 'read my code and tell me where my typos are' (I've done so here already, and I'm sorry for it).
Last edited on
@bnbertha that's what I was trying to angle around to eventaully - that he might be using a c compiler instead of c++ one
Topic archived. No new replies allowed.