473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

error: unqualified id expected question.

Hello there, I am currently writing a small program and cannot compile it. Each time I compile, I end up with a single error in one file and its corresponding header file. For simplicity, I will just include the header file unless requested:
Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2.  
  3. #ifndef DKS_H
  4. #define DKS_H
  5.  
  6. using namespace std;
  7.  
  8. struct item{
  9.     int number;
  10.     float weight;
  11.     float profit;
  12.     float pPERw;
  13. };
  14.  
  15. item[][][] createProfitMatrix(item itemList[], int listSize, int sacWt);
  16.  #endif
  17.  

Now when I compile the files using GNU C++, I get the error:
error: expected unqualified-id before â[â token
on line 15.

I saw that someone had a similar problem here: http://www.thescripts.com/forum/thread141269.html but I could not gather what was wrong with my code from the answers provided.

Thanks for the help.
May 28 '07 #1
1 1656
AdrianH
1,251 Expert 1GB
Hello there, I am currently writing a small program and cannot compile it. Each time I compile, I end up with a single error in one file and its corresponding header file. For simplicity, I will just include the header file unless requested:
Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2.  
  3. #ifndef DKS_H
  4. #define DKS_H
  5.  
  6. using namespace std;
  7.  
  8. struct item{
  9.     int number;
  10.     float weight;
  11.     float profit;
  12.     float pPERw;
  13. };
  14.  
  15. item[][][] createProfitMatrix(item itemList[], int listSize, int sacWt);
  16.  #endif
  17.  

Now when I compile the files using GNU C++, I get the error:
error: expected unqualified-id before â[â token
on line 15.

I saw that someone had a similar problem here: http://www.thescripts.com/forum/thread141269.html but I could not gather what was wrong with my code from the answers provided.

Thanks for the help.
The problem is with the return value.

First, an array must define every dim size with the exception of the first one, that you can leave as empty and it will either be determined by the initialiser, or just treated as a pointer depending on the context.

Second, the return format for an array is not that way. Array syntax is pretty messed in C/C++. What you are probably wanting is this:
Expand|Select|Wrap|Line Numbers
  1. item (createProfitMatrix)(item itemList[], int listSize, int sacWt)[Xsize][Ysize][Zsize];
Which means (if I've done it correctly, and I don't pretend to be sure) that the function will return a 3D array of items, which can be captured by using a item pointer to a 2D array of size [Ysize][Zsize]. NOTE: do not return an auto array (an array that is allocated on the function stack). You have been warned.

Third, it looks like you are writing this in C++, so return a vector of a vector of a vector instead or pointer to such. Working with arrays is not for the faint of heart.

Fourth, if you have allocated the space that is returned by the function, make sure you delete it. Again, you have been warned.


Adrian
May 29 '07 #2

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

Similar topics

4
by: Aaron Walker | last post by:
Greetings, I'm attempting to write my first *real* template function that also deals with a map of strings to member function pointers that is making the syntax a little tricky to get right. ...
5
by: cranium.2003 | last post by:
hi, Here is my code #include <iostream.h> int main() { cout <<"HI"; return 0; } and using following command to compile a C++ program g++ ex1.cpp -o ex1
1
by: liuhaoran | last post by:
HI. i have a question about memory error. when i change double variable to float variable ,for example: int curGen = 0; double sum = 0; // m_iPopSize is int variable ,NewPop is a vector...
3
by: rorni | last post by:
Hi, I'm porting code from Windows to HP-UX 11, compiling with g++. I'm getting a compilation error on the system's debug.h include file, which is included very indirectly through a series of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
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...
0
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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 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.