473,387 Members | 1,771 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,387 software developers and data experts.

expected constructor, destructor, or type conversion before < token

1
Hi,

I have written the following program:

-------------------------------------------------------------------------------------------------------------

1 #include <stdio.h>
2 #include "abc.h"
3
4 void PROP_abc(double ptr[TN][TTS])
5 {
6 double ptr1[TN][TTS] = { 0.1936, 0.17273, 0.63634, 0.9429, 5.4393, 0.77277, 0.025127, 0.14202, 0.55906, 0.38984, 0.00, 0.00, 0.6214, 0.12952, 0.45833, 00.53225, 0.017949, 0.57854, 0.16608, 1.0684, 0.31321, 1.198, 0.00, 0.00, 0.00, 0.025592, 0.00, 0.44234, 0.27205, 0.24618,
7 ............
8 ............
9 ............
10 ............
11 ............
12 ............
13 ............
14 ............};
15 for(int i = 0; i < TN; i++)
16 for(int t = 0; t < TTS; t++)
17 ptr[i][t] = ptr1[i][t];
18 return;
19 }

-------------------------------------------------------------------------------------------------------------

where TN and TTS are defined in file abc.h and the numbers on left are the line numbers.

I am getting following errors:

In function void PROP_abc
1. error: expected `}' before numeric constant in line number 6
2. error: expected â,â or â;â before numeric constant in line number 6

At global scope
3. expected unqualified-id before for in line 15
4. expected constructor, destructor, or type conversion before < token in line 15
5. expected constructor, destructor, or type conversion before ++ token in line 15.
6. expected constructor, destructor, or type conversion before < token in line 16
7. expected constructor, destructor, or type conversion before ++ token in line 16
8. expected unqualified-id before return in line 18
9. expected declaration before } token in line 19

I am surprised to see so many errors but fail to see the reason, please help.

Thank you.
Sep 5 '08 #1
10 15712
Laharl
849 Expert 512MB
You have a 2D array, so each subarray (row) needs to be defined.

Expand|Select|Wrap|Line Numbers
  1. double arr[2][2] = {{2.0, 1.5}, {1.75, 18.32}};
  2.  
Sep 5 '08 #2
Banfa
9,065 Expert Mod 8TB
TN and TTS are defined somewhere are they?

Line 17 is not going to work because ptr1 is not a 2 dimensional array of double but rather a double **. As such there is no first dimension size required for the compiler to be able to properly calculate the location you are talking about.
Sep 5 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Line 17 is not going to work because ptr1 is not a 2 dimensional array of double but rather a double **. As such there is no first dimension size required for the compiler to be able to properly calculate the location you are talking about.
ptr1 is the address of ptr1[0]. ptr1[0] is an array of TTS doubles. Therefore, ptr1 is a pointer to an array of TTS doubles:

double (*ptr1)[TTS];

ptr1 is not a double**.


As to array dimension size, assuming TN and TTS are global constants, the compiler does have all the informaton it needs for pointer arithmetic.

The code as posted compiles OK.

The posted errors are outside the posted code.
Sep 5 '08 #4
Banfa
9,065 Expert Mod 8TB
ptr1 is the address of ptr1[0]. ptr1[0] is an array of TTS doubles. Therefore, ptr1 is a pointer to an array of TTS doubles:

double (*ptr1)[TTS];

ptr1 is not a double**.
True my mistake I was talking about ptr not ptr1 which is a double ** but is accessed as a 2d array and that highlights the problems with having your variable names too similar.
Sep 6 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
True my mistake I was talking about ptr not ptr1 which is a double **
ptr is not a double** either. This code:
void PROP_abc(double ptr[TN][TTS])
5 {
6 double ptr1[TN][TTS] = { 0.1936, 0.17273, 0.63634, 0.9429, 5.4393, 0.77277, 0.025127, 0.14202, 0.55906, 0.38984, 0.00, 0.00, 0.6214, 0.12952, 0.45833, 00.53225, 0.017949, 0.57854, 0.16608, 1.0684, 0.31321, 1.198, 0.00, 0.00, 0.00, 0.025592, 0.00, 0.44234, 0.27205, 0.24618,
etc....
shows ptr is an array of TN elements that are TTS arrays of double. That makes ptr a pointer to and array of TTS doubles just like ptr1.

Where is this double** coming from? There's no double** anywhere in the posted code.
Sep 6 '08 #6
Banfa
9,065 Expert Mod 8TB
ptr is not a double** either. This code:


shows ptr is an array of TN elements that are TTS arrays of double. That makes ptr a pointer to and array of TTS doubles just like ptr1.

Where is this double** coming from? There's no double** anywhere in the posted code.
I believe ptr is a double ** because it is declared as a function parameter. You can't pass arrays as function parameters (or is that something that has changed between C and C++?) and the notation [] used on a function parameter is equivalent to declaration of a pointer rather than declaration of an array.
Sep 7 '08 #7
Laharl
849 Expert 512MB
It's not a double**. It's a double*[]. There's a difference because the latter implies that all of the rows are the same length (a value the compiler needs to generate valid assembly).
Sep 7 '08 #8
Parul Bagadia
188 100+
It's not a double**. It's a double*[]. There's a difference because the latter implies that all of the rows are the same length (a value the compiler needs to generate valid assembly).
what are the signs after double; are they for pointer?
Sep 7 '08 #9
Banfa
9,065 Expert Mod 8TB
what are the signs after double; are they for pointer?
Yes .
Sep 7 '08 #10
weaknessforcats
9,208 Expert Mod 8TB
I believe ptr is a double ** because it is declared as a function parameter. You can't pass arrays as function parameters (or is that something that has changed between C and C++?) and the notation [] used on a function parameter is equivalent to declaration of a pointer rather than declaration of an array.
True, you cannot pass an array to a function because the name of the array is the address of element 0. Therefore, what you pass is that address.

In this case, there is an array of double [TN][TTS] that belongs to the caller. When that array is passed to a function, what is passed is the address of element 0. In this case element 0 is an array of double [TTS]. Therefore, what is passed is the address of this element. And that is a double(*)[TTS].

So the correct function argument is double ptr[TN][TTS] or double ptr[][TTS].

In the first case the function knows there are TN elements in the array. In rthe second case, that information should be passed as a second argument.

A double** is a pointer to a double* and a double* is a pointer to a single double. None of this applies to the current code.

It is true that the address of the array and the address of element 0 are the same address. So you could lie to the compiler and typecast to a double** and handle the dimensions with two addtional function arguments.

Since all arrays in C and C++ are one-dimensional arrays, you can typecast as needed to view the array in any manner desired.

Finally, try compiling this code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. void MyFunc(double** arg)
  3. {
  4.  
  5. }
  6. int main()
  7. {
  8.    const int TN = 5;
  9.    const int TTS = 10;
  10.    double arr[TN][TTS];
  11.    MyFunc(arr);
  12.  
  13. }
  14.  
and see what your compiler says about this. If you are right, this will compile without error.
Sep 7 '08 #11

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

Similar topics

6
by: Zenon | last post by:
Folks, I cannot figure out why I am getting an error: Error E2303 EngineX.hpp 19: Type name expected. Here is my code. Can you please help? #ifndef EngineX__hpp #define EngineX__hpp ...
5
by: Preben | last post by:
Hi, I get this error when trying to compile: -------- # g++ -c KGreyImage.cpp KGreyImage.cpp:25: error: expected constructor, destructor, or type conversion before '*' token --------
10
by: Szabolcs Horvát | last post by:
Consider the attached example program: an object of type 'A' is inserted into a 'map<int, Am;'. Why does 'm;' call the copy constructor of 'A' twice in addition to a constructor call? The...
5
by: Damien | last post by:
Hi all, I'm using a pretty standard C++ Singleton class, as below: template <typename T> class Singleton { public: static T* Instance() {
2
by: algatt | last post by:
Hello, I am trying to compile the TPIE files but there is a file that's constantly giving errors about the templates. I am using gcc 3.4.5 on Eclipse using Windows XP. The following is the code of...
5
by: amitmool | last post by:
hi, i have used the queue library file and try to use the template as template <class QueueItem> queue <QueueItem>::~queue() // line 25 { } template <class QueueItem> void...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
2
by: parvtb | last post by:
I have the following code: #include <list> using namespace std; template <typename T> list<T>::iterator doStuff( list<T>::iterator myIter ) //--error here
11
by: Peter Jansson | last post by:
Dear newsgroup, In the following code, it looks as though the exception thrown in the constructor is not caught properly. I get this output: ---- standard output ---- Base() constructor....
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.