Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing objects as arguments

Status
Not open for further replies.

csripriya1

Programmer
May 13, 2003
35
0
0
US
Hi all,
I have some weird problems with passing objects as arguments. I have 2 functions which takes objects as arguments.I have some printing statement in the last line of both the functions. When I call these functions from main,This last printing statement gets executed and then the executables crashes off. I am compiling and running it in Visual C++.When I ask for the debug option it gives unhandled exception and access violation.I am wondering why this happens.

Can anyone help me with this.
Thanks
 
Hi,
In the definition of class I declared the function prototype like this in the funcgpid.h header file.

void get_4thcoord(float[4][3],funcgps,funcgps);

In this the second and third argument corresponds to objects of the classes funcgps.

The function definition goes like this:

void funcgps::get_4thcoord(float coord[4][3],funcgps fg1,funcgps fg2)
{
.......
.........
.......
........
for(j=0;j<3;j++)
{
coord[ii][j]=coord[ii][j]+coord[1][j];
cout<<coord[ii][j]<<&quot; &quot;;

}
cout<<endl;




cout<<coord[3][0]<<&quot; &quot;<<coord[3][1]<<&quot; &quot;<<coord[3][2]<<endl;

}
the main function where I call this function, looks like this


#include &quot;funcgpid.h&quot;
int main()
{
...............
..............
..............
funcgps ppfg1,ppfg2;
float copycoords[4][3]={0};

for(i=0;i<4;i++)
for(j=0;j<3;j++)
copycoords[j]=co_ords[j];

sdf1.get_4thcoord(copycoords,ppfg1,ppfg2);
cout<<&quot;I am out of the 4th coordinate function&quot;<<endl;

}
While compiling I didn't get any error. But while running the executable the line with the values of coord[3][0],coord[3][1],coord[3][2] are printed.But before printing this line &quot;I am out of the 4th coordinate function&quot; the executable crashes.Then the Debug option of Visual C++ gives handline error and access violation.Can anyone help me with this.
Thanks for the help and your time.
 
You still cut out some of the code. What is the sdf1 object in main? How are the two objects used in the function? My understanding is that the question was about the usage of objects as parameters. Can't help unless we can see what you're doing with them.

JasonD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top