473,657 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compile error about void*

200 New Member
Hello everyone,


What is wrong with the code, I just want to allocate an array of 100 void* pointers. :-)

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     void** p;
  4.  
  5.     p = new (void*) [100];
  6.  
  7.     return 0;
  8. }
  9.  
>d:\visual studio 2008\projects\t est_void1\test_ void1\main.cpp( 5) : error C2143: syntax error : missing ';' before '['
1>d:\visual studio 2008\projects\t est_void1\test_ void1\main.cpp( 5) : error C3409: empty attribute block is not allowed
1>d:\visual studio 2008\projects\t est_void1\test_ void1\main.cpp( 5) : error C2143: syntax error : missing ']' before 'constant'
1>d:\visual studio 2008\projects\t est_void1\test_ void1\main.cpp( 5) : error C2143: syntax error : missing ';' before 'constant'
1>d:\visual studio 2008\projects\t est_void1\test_ void1\main.cpp( 5) : error C2143: syntax error : missing ';' before ']'
1>d:\visual studio 2008\projects\t est_void1\test_ void1\main.cpp( 5) : error C2143: syntax error : missing ';' before ']'


thanks in advance,
George
Jan 17 '08 #1
18 2251
Savage
1,764 Recognized Expert Top Contributor
You just remove those '()' around void*,and it should compile.

Expand|Select|Wrap|Line Numbers
  1. p = new void* [100];
Jan 17 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Use of void* deprecated in C++.
Jan 17 '08 #3
George2
200 New Member
Thanks Savage,


Why adding () does not work, which C++ rule is violated?

You just remove those '()' around void*,and it should compile.

Expand|Select|Wrap|Line Numbers
  1. p = new void* [100];

regards,
George
Jan 18 '08 #4
George2
200 New Member
Why weaknessforcats ?


Any links for this topic and using what to replace void*?

Use of void* deprecated in C++.

regards,
George
Jan 18 '08 #5
Savage
1,764 Recognized Expert Top Contributor
Thanks Savage,


Why adding () does not work, which C++ rule is violated?




regards,
George
Expand|Select|Wrap|Line Numbers
  1. p = new (void*) [100];
this is interpreted by compiler as:

Expand|Select|Wrap|Line Numbers
  1. p=(new unknown_type) (void*)[100];
because of new operator precedence.
Jan 18 '08 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
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.
Jan 18 '08 #7
Savage
1,764 Recognized Expert Top Contributor
C++ ain't C.

In C++ new(void*) is a function named new that has a void* arguiment.



Function overloading.
What about this then:

Expand|Select|Wrap|Line Numbers
  1. void foo();
  2. void (**p)();
  3.  
  4. p = new (void (*[3])());
  5. p[0] = f;
  6.  
  7. //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?
Jan 18 '08 #8
George2
200 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. void foo();
  2. void (**p)();
  3.  
  4. p = new (void (*[3])());
  5. p[0] = f;
  6.  
  7. //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
Jan 19 '08 #9
George2
200 New Member
Thanks Savage,


Could you explain why the code will be explained to

Expand|Select|Wrap|Line Numbers
  1. p=(new unknown_type) (void*)[100];
please?

What is unknown_type comes from? What is new operator precedence?

Expand|Select|Wrap|Line Numbers
  1. p = new (void*) [100];
this is interpreted by compiler as:

Expand|Select|Wrap|Line Numbers
  1. p=(new unknown_type) (void*)[100];
because of new operator precedence.

regards,
George
Jan 19 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2138
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=' in '*this = CTest::operator+(CTest&)((+t2))' test2.cpp:49: error: candidates are: CTest CTest::operator=(CTest&) make: *** Error 1
8
16834
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) ============== %{ #include <iostream> #include "http_parser.tab.hpp"
10
19708
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 have a struct that contains several different types of data. This struct is used throuout the program. Now, when I compile, I get 6 errors, all of them "Use of possibly unassigned field 'awayTime'" or "Use of possibly unassigned field 'intlTime'"....
1
1982
by: ranges22 | last post by:
****************************************************************** I am compiling a librarry which has a .h file containing th following: ****************************************************************** template<typename T> void from_string(const char Str, T &Obj); template<> void from_string(const char Str, long &); // template<> void from_string(const char Str, unsigned lon &); //
1
5386
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: Project: drawing_control, Configuration: Release Win32 ------ 1>Deleting intermediate and output files for project 'drawing_control', configuration 'Release|Win32'
1
3398
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 program. that's the program (i named it alle.c): #include <stdio.h> #include <stdlib.h>
1
2122
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: http://boinc.berkeley.edu/. I get the folllowing errors when I want to compile their default application (WinXP, MSVC++E05):
12
2752
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() { // ... }
2
6351
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 : $ ../glibc-2.5/configure --prefix=/mnt/new/Mars/glibc_HQ_test/GLIBC/ install/ --with-__thread --enable-kernel=2.6.11 --enable-shared
7
5764
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 compiled no problem. But I can't find the what the problem is with templates? Please help. The main is in test-linked-list.cpp. There are two template classes. One is List1, the other one is ListNode. The codes are below: // test-linked-list.cpp :...
0
8316
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8737
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.