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

float m[4][3];

For

float a[9];

we know just using the array name a gives a float* to the first
element in the array.

For

float m[4][3];

what is the type of the array name m?

Jul 30 '07 #1
7 1605
xo****@yahoo.com wrote:
For

float a[9];

we know just using the array name a gives a float* to the first
element in the array.

For

float m[4][3];

what is the type of the array name m?
Since 'm' is an array of arrays, the array-to-pointer conversion of
'm' would yield a pointer to an array.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 30 '07 #2
On Jul 30, 8:01 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
xon...@yahoo.com wrote:
For
float a[9];
we know just using the array name a gives a float* to the first
element in the array.
For
float m[4][3];
what is the type of the array name m?

Since 'm' is an array of arrays, the array-to-pointer conversion of
'm' would yield a pointer to an array.
Okay, then why doesn't this work? Isn't T* d[3] a pointer to an
array?

#include <iostream>
using namespace std;

template<typename T>
class C
{
public:
C(T* d[3], int m, int n)
{
mData = new T*[m];
for(int i = 0; i < m; ++i)
mData[i] = new T[n];

for(int i = 0; i < r; ++i)
for(int j = 0; j < c; ++j)
mData[i][j] = d[i][j];

r = m;
c = n;
}

~C()
{
for(int i = 0; i < r; ++i)
delete[] mData[i];

delete[] mData;
}

T& operator()(int i, int j)
{
return mData[i][j];
}

void print()
{
for(int i = 0; i < r; ++i)
{
for(int j = 0; j < c; ++j)
{
cout << data[i][j] << "\t";
}
cout << endl;
}
}

private:
T** data;
int r;
int c;
};

int main()
{
float m[2][3];
m[0][0] = 1.0f;
m[0][1] = 2.0f;
m[0][2] = 3.0f;
m[1][0] = 4.0f;
m[1][1] = 5.0f;
m[1][2] = 6.0f;
m[2][0] = 7.0f;
m[2][1] = 8.0f;
m[2][2] = 9.0f;

C<floatT(m, 2, 3);

T.print();
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Jul 30 '07 #3
xo****@yahoo.com wrote:
On Jul 30, 8:01 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>xon...@yahoo.com wrote:
>>For
>>float a[9];
>>we know just using the array name a gives a float* to the first
element in the array.
>>For
>>float m[4][3];
>>what is the type of the array name m?

Since 'm' is an array of arrays, the array-to-pointer conversion of
'm' would yield a pointer to an array.

Okay, then why doesn't this work? Isn't T* d[3] a pointer to an
array?
No,

T *d[3]

is an array of three pointers. You need to use parentheses.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 30 '07 #4
On Jul 30, 11:08 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
xon...@yahoo.com wrote:
On Jul 30, 8:01 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
xon...@yahoo.com wrote:
For
>float a[9];
>we know just using the array name a gives a float* to the first
element in the array.
>For
>float m[4][3];
>what is the type of the array name m?
Since 'm' is an array of arrays, the array-to-pointer conversion of
'm' would yield a pointer to an array.
Okay, then why doesn't this work? Isn't T* d[3] a pointer to an
array?

No,

T *d[3]

is an array of three pointers. You need to use parentheses.
It still didn't work. How did you do the parentheses?
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Jul 30 '07 #5
<xo****@yahoo.comwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
: >float m[4][3];
: >
: >what is the type of the array name m?
: >
: Since 'm' is an array of arrays, the array-to-pointer conversion
of
: 'm' would yield a pointer to an array.
: >
: Okay, then why doesn't this work? Isn't T* d[3] a pointer to an
: array?
: >
: No,
: >
: T *d[3]
: >
: is an array of three pointers. You need to use parentheses.
:
: It still didn't work. How did you do the parentheses?

Did you try:
T (*d)[3]
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form

Jul 30 '07 #6
Did you try:
T (*d)[3]
Thank you, I was doing it wrong.

So just in how I should read this:

T* d[3] = "d is an array of 3 T*"

T (*d)[3] = "d is a pointer to a T[3]"

hth -Ivan
--http://ivan.vecerina.com/contact/?subject=NG_POST<- email contact form

Jul 30 '07 #7
xo****@yahoo.com wrote:
>Did you try:
T (*d)[3]

Thank you, I was doing it wrong.

So just in how I should read this:

T* d[3] = "d is an array of 3 T*"

T (*d)[3] = "d is a pointer to a T[3]"
Right. By extension,

T (*d[5])[3] = "d is an array of 5 pointers to T[3]"

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 30 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pat | last post by:
Give two double-typed variable X and Y. If (X==Y) is true, then how about the following results: (float(X) > float(Y))? (float(X) < float(Y))? (float(X) >= float(Y))? ( X > float(Y) )? ( X...
14
by: Glen Able | last post by:
Should it be possible to create a custom class, 'Float', which would behave as a drop-in replacement for the builtin float type? As mentioned in another thread, I once tried this in rather a...
16
by: Gerald Lafreniere | last post by:
{ float F=123.456000; F*=1000; // Actually I used a for loop F*=10 three times. printf("%f\n", F); } This will produce something like 123456.00XXXX, where XXXX are garbage digits. Why...
6
by: Dave win | last post by:
Hi all: I'm confused with the expression "(float *())". Book says that this is a cast. But, I have no idea of this expr. why could this expr ignore the variable??? Thanx!!!
9
by: Sisyphus | last post by:
Hi, I have some software that does the following (in an attempt to determine whether the double x, can be represented just as accurately by a float): void test_it(double x) { float y = x;...
11
by: Marc Pelletier | last post by:
Hello, I am having trouble implementing the following callback: CNCSError CECWCompressor::WriteReadLine(UINT32 nNextLine, void **ppInputArray) where ppInputArray is a 3 by x array. The...
20
by: ehabaziz2001 | last post by:
That program does not yield and respond correctly espcially for the pointers (*f),(*i) in print_divide_meter_into(&meter,&yds,&ft,&ins); /*--------------pnt02own.c------------ ---1 inch = 2.51...
8
by: vjnr83 | last post by:
Hi, I have a doubt: what is the difference between float **p and float *p? Thanks in advance, Vijay
13
by: Shirsoft | last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding error in the 8th digit. Unfortunately because of the algorithm we use, the errors percolate into higher digits. C++ code is...
3
by: Arnie | last post by:
Folks, We ran into a pretty significant performance penalty when casting floats. We've identified a code workaround that we wanted to pass along but also was wondering if others had experience...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
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,...

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.