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.
10 15749 Laharl 849
Recognized Expert Contributor
You have a 2D array, so each subarray (row) needs to be defined. -
double arr[2][2] = {{2.0, 1.5}, {1.75, 18.32}};
-
Banfa 9,065
Recognized Expert Moderator Expert
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.
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.
Banfa 9,065
Recognized Expert Moderator Expert
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.
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.
Banfa 9,065
Recognized Expert Moderator Expert
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.
Laharl 849
Recognized Expert Contributor
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).
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?
Banfa 9,065
Recognized Expert Moderator Expert
what are the signs after double; are they for pointer?
Yes .
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
#include<iostream>
#include <cstring>
#include <cmath>
|
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
--------
|
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 constructors and copy constructors in 'A' report when they are
called. 'whoami' is just a unique identifier assigned to every object of
type 'A'. The output of the program is:
constructor 0
constructor 1
|
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()
{
|
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 the file that I am trying to compile:
// Copyright (c) 1994 Darren Erik Vengroff
//
// File: ami_scan_mac.h
// Author: Darren Erik Vengroff <dev@cs.duke.edu>
// Created: 5/24/94
//
// $Id: ami_scan_mac.h,v 1.10 2003/04/25 00:06:56 tavi Exp $
| |
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 queue<QueueItem>::push(const QueueItem& entry) // line 42
|
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?
class Trial
{
public: Trial()
{
|
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
|
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.
Exception in Base(): "Going down (B can't be
construced properly)!"
(the exception has now been dealt with).
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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,...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| | |