TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JOSHUA BOEHME
from: THOMAS MAEDER
date: 1997-04-27 19:22:00
subject: Pointer Arrays

JB> void battle(int id[])
JB> {
JB> int num = sizeof(id) / sizeof(int);  // A variable number of objects
This  is  wrong.  id  is  passed to battle() as a pointer to its first
element, so
sizeof id == sizeof(int *)
Either you can use a collection class (e.g. the vector template of the
Standard C++ Library) or pass id's length as a second parameter.
Thomas
---
 þ MM 1.0 #0113 þ Nothing is so smiple that it can't get screwed up.
---------------
* Origin: McMeier & Son BBS (2:301/138)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.