473,406 Members | 2,259 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,406 software developers and data experts.

passing array or arrays.

I get the error:

"error C2664: 'C<T>::C(T **,int,int)' : cannot convert parameter 1
from 'float [2][3]' to 'float **'"

An array of array does not get resolved to a pointer-to-pointer?

#include <iostream>
using namespace std;

template<typename T>
class C
{
public:
C(T** d, 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();
}

Jul 24 '07 #1
1 1467
On Jul 25, 1:35 am, xon...@yahoo.com wrote:
I get the error:
"error C2664: 'C<T>::C(T **,int,int)' : cannot convert parameter 1
from 'float [2][3]' to 'float **'"
An array of array does not get resolved to a pointer-to-pointer?
No. Why should it? An array is converted implicitly to a
pointer, but the result of that conversion is a pointer, not an
array, so no further conversions of the sort apply.

Think about how pointers work, and what the layout of the
various types is in memory, and you'll quickly see why it
couldn't be otherwise. In particular, think about the
implications on pointer arithmetic (which also should explain
why in a pointer to an array, the dimension of the array must be
known).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 25 '07 #2

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

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
10
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences...
3
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes...
2
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short...
2
by: sonaliagr | last post by:
I am trying to update a msg array in function by passing the address but it is showing an error. and also, i want the value of msg array to be accessible to the full code that is inside the main...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: Fizzics | last post by:
This is my first post here at Bytes. I have been trolling it, mostly with the help of Google searches, for some time now. I have done about all of the searching and reading that I really know how to...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...
0
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...

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.