|
Hi DavidCrow,
I want to allocate 100 void* type, so I add () besides void*, it is natural thinking, right?
regards,
George
|
|
|
|
|
George_George wrote: it is natural thinking, right?
How would you allocate 100 ints or chars?
int *n = new int[100];
int *c = new char[100]; Why would void* be any different?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi DavidCrow,
The same for int*. Here is my code,
int main()
{
int** p;
p = new (int*) [100];
delete[] p;
return 0;
}
regards,
George
|
|
|
|
|
George_George wrote: p = new (int*) [100];
You've already been told this will not work. Why do you continue to suggest it should?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Your sample also breaks if you add () between int.
My code,
int main()
{
int* p;
p = new (int) [100];
delete[] p;
return 0;
}
will get the same compile errors as I posted in the beginning of this question. Any ideas?
regards,
George
|
|
|
|
|
George_George wrote: Your sample also breaks if you add () between int.
This should come as no surprise since it would therefore be a syntax error.
Are you being thick-headed on purpose? You've already been told (more than once) that parenthesis are not allowed around the type.
int *p = new int[100];
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
I just recite this rule. Well...
I am just curious how compiler will interpret this statement if I add (), and why if I add (), there are so many strange errors. Just personal curious how compiler treat this than simply recite this rule.
regards,
George
|
|
|
|
|
George_George wrote: I am just curious how compiler will interpret this statement if I add ()...
Once the compiler encountered the left bracket, it complained. That should have been enough to lead you to what was wrong.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for your patience, DavidCrow!
My question is answered.
regards,
George
|
|
|
|
|
The syntax you are using with the parens is how you call placement new , and the way you would be calling placement new is incorrect.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks James, Cool!
We have never thought of this.
regards,
George
|
|
|
|
|
|
Thanks Hamid,
But I do not think it relates to my question.
have a nice weekend,
George
|
|
|
|
|
It was more info about void*.
|
|
|
|
|
What do you mean Hamid? I do not quite catch your points.
have a good weekend,
George
|
|
|
|
|
I said it was for more info about void pointers.
Thanks but I think I must tell you have a good weekend because my holiday is Fridays not Sat and sundays
|
|
|
|
|
Thanks Hamid!
regards,
George
|
|
|
|
|
You're welcome.
May I ask a question?
|
|
|
|
|
Sure, Hamid.
regards,
George
|
|
|
|
|
I asked a question of you before but I dont know why you didnt answer to me anyway I saw your profile that you live in china,so I have some questions of you:
I like to see China because I like China and China people (of course I dont know I shall be successed or no),so I want to learn China language, I seached on the internet but I couldnt find good site for learn it because I must know pronunciation of alphabet and how can I write China's character (do you know a good site for it) I think its difficult for me and other question where's nice places on China.
|
|
|
|
|
Hi Hamid,
I have answered you before. Please check your private message box.
regards,
George
|
|
|
|
|
I didnt get any thing.
|
|
|
|
|
I have sent again, still not received?
regards,
George
|
|
|
|
|
|
Could you check with your email please? I always reply with Email option.
regard,
George
|
|
|
|