I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
Go Back  Xtreme Visual Basic Talk > > > I can't understand why this simple code doesn't complile


Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2013, 02:20 AM
naton naton is offline
Freshman
 
Join Date: Aug 2004
Posts: 30
Default I can't understand why this simple code doesn't complile


Hi there,

I'm playing with arrays and pointers in VC++ 2005 and don't understand why this code gives me a "error C2109: subscript requires array or pointer type" while the one below it compiles just fine. The array passed to this function is a 2 dimensional array: myArray[size1D][size2D], and is declared elsewhere in the form.

Code:
void Print2DArrayToScreen (int size1D, int size2D, int *pArray)
{
	String^ tmpStr = gcnew String(String::Empty);

	for (int i = 0; i < size1D; i++)
		for (int j = 0; j < size2D; j++)
			MessageBox::Show(pArray[i][j].ToString());
}
Code:
void Print2DArrayToScreen (int size1D, int size2D, int *pArray)
{
	String^ tmpStr = gcnew String(String::Empty);

	for (int i = 0; i < size1D; i++)
		for (int j = 0; j < size2D; j++)
			MessageBox::Show(*(pArray + (i * size2D) + j)).ToString());
}
Aren't the following two expressions equal?

pArray[i][j] = *(pArray + (i * size2D) + j)

Thanks.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
 
I can't understand why this simple code doesn't complile
I can't understand why this simple code doesn't complile
 
-->