GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Sep-2005, 08:00
pixienick pixienick is offline
New Member
 
Join Date: Aug 2005
Posts: 23
pixienick is on a distinguished road

array function argument


Hi
i know this is kind of an old question but i'm having real difficulty getting an array into a function and copying it to somewhere else. The problem is compounded by the fact the array is a class CPoint and the function is a member of a CDoc derivative being called from a CView derivative. It looks like this;
CPP / C++ / C Code:
void CStereoScopicDoc::NewPoly(int viewAB, CPoint points[], int selectedNum)
{
    //this bits alright *******************
	PolySelect *pTemp = pPolyList;

	while(pTemp->done)
	{
		if(pTemp->next)
			pTemp = pTemp->next;
		else
			break;
	}
	
	//its just here
	pTemp->Enter(PolySelectNum, viewAB, points, selectedNum);
	


}
as you can see i'm passing the array again to another function of another class, but i think the problem has already occurred. Looking at the watch window in debug the array is filled before it is passed to this function, but the points[] array in this function only appears to have the first element. Here's a bit of the Enter function of the 'PolySelect' class;
CPP / C++ / C Code:
void PolySelect::Enter(int in_ID, int viewAB, CPoint points[], int num)
{
	ID = in_ID;

	pointNum = num;

	if(viewAB == 1)
	{
		//imID_A = imID;
		selectA = new CPoint[num];

               //its here where it all goes wrong!!
		for(int i=0; i<num; i++)
		{
			selectA[i] = points[i];
		}
		doneA = true;
	}
//etc
You see i want to copy the data over not just pass the pointer. Can anyone tell me where i'm going wrong? And, just to check, it is true that declaring a function parameter as a pointer is the same as declaring it like an array? The program compiles and runs but dosen't do what i want.
Once again, any help much appreciated.
Nick
  #2  
Old 01-Sep-2005, 09:57
Kacyndra's Avatar
Kacyndra Kacyndra is offline
Member
 
Join Date: May 2005
Location: Maryland
Posts: 225
Kacyndra will become famous soon enough
hey
what are you trying to do by this:
Code:
pTemp->Enter(PolySelectNum, viewAB, points, selectedNum);

hm........ i'v never seen anyone call a function this way before.
__________________
Xrum!
  #3  
Old 02-Sep-2005, 04:34
pixienick pixienick is offline
New Member
 
Join Date: Aug 2005
Posts: 23
pixienick is on a distinguished road
Well you haven't done alot of c++ then have you?

pTemp is a pointer to an object of type PolySelect, you see it declared like
CPP / C++ / C Code:
 PolySelect *pTemp 
Because it's a pointer and not an actual piece of data you refer to it's member functions and variables with -> instead of a dot. So 'Enter' is a member function of PolySelect and the rest of it is the function arguments.
Funky init?
Know anything about passing arrays to functions, by the way?
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Pointer Usage in C++: Beginner to Advanced varunhome CPP / C++ Forum 0 19-Aug-2005 09:25
template comiling problems - need expert debugger! crq CPP / C++ Forum 1 01-Feb-2005 21:26
Revising Script style ?????? pepee MySQL / PHP Forum 4 14-Apr-2004 04:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:54.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.