Hello everyone,
What is wrong with the code, I just want to allocate an array of 100 void* pointers. :-) -
int main()
-
{
-
void** p;
-
-
p = new (void*) [100];
-
-
return 0;
-
}
-
>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ';' before '['
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C3409: empty attribute block is not allowed
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ']' before 'constant'
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ';' before 'constant'
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ';' before ']'
1>d:\visual studio 2008\projects\test_void1\test_void1\main.cpp(5) : error C2143: syntax error : missing ';' before ']'
thanks in advance,
George
18 2232
You just remove those '()' around void*,and it should compile.
Use of void* deprecated in C++.
Thanks Savage,
Why adding () does not work, which C++ rule is violated?
You just remove those '()' around void*,and it should compile.
regards,
George
Why weaknessforcats?
Any links for this topic and using what to replace void*?
Use of void* deprecated in C++.
regards,
George
Thanks Savage,
Why adding () does not work, which C++ rule is violated?
regards,
George
this is interpreted by compiler as: - p=(new unknown_type) (void*)[100];
because of new operator precedence.
p = new (void*) [100];
C++ ain't C.
In C++ new(void*) is a function named new that has a void* arguiment.
Why weaknessforcats?
Any links for this topic and using what to replace void*?
Quote:
Originally Posted by weaknessforcats
Use of void* deprecated in C++.
Function overloading.
C++ ain't C.
In C++ new(void*) is a function named new that has a void* arguiment.
Function overloading.
What about this then: - void foo();
-
void (**p)();
-
-
p = new (void (*[3])());
-
p[0] = f;
-
-
//etc...
Is this interpreted as a overloaded function called new that takes a pointer to the array of generic function pointers,or does it allocate memory for p?
Thanks Savage,
I have tried your code can compile. What does the following statement mean?
p = new (void (*[3])());
what is the type of p? Could you interpret the meaning of right side of assignment and left side of assignment please?
What about this then: - void foo();
-
void (**p)();
-
-
p = new (void (*[3])());
-
p[0] = f;
-
-
//etc...
Is this interpreted as a overloaded function called new that takes a pointer to the array of generic function pointers,or does it allocate memory for p?
regards,
George
Thanks Savage,
Could you explain why the code will be explained to - p=(new unknown_type) (void*)[100];
please?
What is unknown_type comes from? What is new operator precedence?
this is interpreted by compiler as: - p=(new unknown_type) (void*)[100];
because of new operator precedence.
regards,
George
Yes, weaknessforcats.
I agree "In C++ new(void*) is a function named new that has a void* arguiment", and the global new operator function is invoked.
But, does it has anything to do with my question (compile error)? Could you provide more description please?
C++ ain't C.
In C++ new(void*) is a function named new that has a void* arguiment.
Function overloading.
regards,
George
I agree "In C++ new(void*) is a function named new that has a void* arguiment", and the global new operator function is invoked.
If you agree that new(void*) is a function named new that has a void argument, then you have answered your own question. You are not allowed to have a function with the same name as a C++ keyword.
Thanks weaknessforcats,
In below statements, you mean system global new function?
If you agree that new(void*) is a function named new that has a void argument, then you have answered your own question.
regards,
George
No I do not. new is a keyword. You can't use new as a function name.
I think you may confusing the keyword new with the function
operator new() that is called to allocate memory. I'm not making this up. The new operator calls operator new.
Thanks weaknessforcats,
Now I understand you mean operator new. :-)
This is what you mentioned before,
--------------------
If you agree that new(void*) is a function named new that has a void argument, then you have answered your own question.
--------------------
Why if I agree I should answer it by myself? I am confused. So, you mean you think in my question the operator new which takes void* as input argument take effect?
No I do not. new is a keyword. You can't use new as a function name.
I think you may confusing the keyword new with the function
operator new() that is called to allocate memory. I'm not making this up. The new operator calls operator new.
regards,
George
What the compiler sees is new(void*).
That is a function named new that has a void* argument.
That is an error because new is a reserved C++ keyword.
End of discussion.
Thanks for your help, weaknessforcats!
I think when adding (), the placement form of new is invoked, right?
What the compiler sees is new(void*).
That is a function named new that has a void* argument.
That is an error because new is a reserved C++ keyword.
End of discussion.
regards,
George
That is correct. -
char array[1000];
-
int* arr = new (array) int[5];
-
The int array is allocated inside the char array.
Thanks weaknessforcats!
My question is answered.
That is correct. -
char array[1000];
-
int* arr = new (array) int[5];
-
The int array is allocated inside the char array.
regards,
George
Sign in to post your reply or Sign up for a free account.
Similar topics
by: xuatla |
last post by:
Hi,
I encountered the following compile error of c++ and hope to get your help.
test2.cpp: In member function `CTest CTest::operator+=(CTest&)':
test2.cpp:79: error: no match for 'operator='...
|
by: pavel.orehov |
last post by:
Hi,
I am using flex and bizon to write HTTP parser.
I am passing well flex and bison tools but can't compile their output.
================= Flex file (http_parser.lpp) ==============
%{...
|
by: Chris LaJoie |
last post by:
Our company has been developing a program in C# for some time now, and we
haven't had any problems with it, but just last night something cropped up
that has me, and everyone else, stumped.
I...
|
by: ranges22 |
last post by:
******************************************************************
I am compiling a librarry which has a .h file containing th
following:...
|
by: electrixnow |
last post by:
Help!,
I need to compile this code with static libs so it run on another XP
machine that does'nt have
MS Studio installed. When I compile now I get an ERROR:
1>------ Rebuild All started:...
|
by: HugoScripts |
last post by:
hi there,
as i said i'm trying to compile a simple program that uses allegro, it's a small thing, indeed my goal was just to start using allegro, but until now i'm unable even to compile my simple...
|
by: Jonas Schneider |
last post by:
Heya,
donīt know if you know BOINC: itīs a system for distributed computing,
therefore distributing work to many computers and creating a little
super-computer, see also their homepage:...
|
by: Ioannis Vranos |
last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard,
something simple like defining a function as:
void somefunc(void) throw()
{
// ...
}
|
by: akhilesh.noida |
last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting
errors while configuring it. Please check and give your inputs for
resolving this.
configure command :
$...
|
by: QiongZ |
last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |