954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Passing Arrays of Objects to Member Functions

Dear all,

I have written a program in c++ to pass arrays of objects(belonging to the same class) to a member function. It works fine in VC++ but gives an error as "Undefined structure class name". My program is a larger one. So i am giving a similar code below. Pls help me. Your replies are highly appreciated. Thanking you.

#include
#include

class test
{
int k;
public:
void fun(test t[])
{
cout<<"Test program....";
}
};

void main()
{
test t;
test r[2];
t.fun(r);
getch();
}


Regds,
Beuls

beuls
Light Poster
40 posts since Jan 2006
Reputation Points: 13
Solved Threads: 2
 
It works fine in VC++ but gives an error as "Undefined structure class name".


How can it work and give you an error at the same time?

See the changed code...and before asking why I changed some lines...do a search of this forum or google...

#include <iostream>
using namespace std;
class test
{
int k;
public:
void fun(test t[],int size)
{
cout<<"Test program....";
}
};

int main()
{
test t;
test r[2];
t.fun(r,2);
return 0;
}
SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

Thanks for your reply. The code works well in VC++ whereas it gives the error "Undefined structure class name" in Turbo C++.

Beuls

How can it work and give you an error at the same time?

See the changed code...and before asking why I changed some lines...do a search of this forum or google...

#include <iostream>
using namespace std;
class test
{
int k;
public:
void fun(test t[],int size)
{
cout<<"Test program....";
}
};

int main()
{
test t;
test r[2];
t.fun(r,2);
return 0;
}
beuls
Light Poster
40 posts since Jan 2006
Reputation Points: 13
Solved Threads: 2
 

don't use turbo c again

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

Thank you for ur reply. But i am working as a lecturer and have to teach Turbo C for my students.

Beuls

beuls
Light Poster
40 posts since Jan 2006
Reputation Points: 13
Solved Threads: 2
 
But i am working as a lecturer and have to teach Turbo C for my students. Beuls


I am sure you don't have a reason(atleast a valid one)to teach C/C++ using that crappy compiler.

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You