Shashank Shashank - 3 months ago 13
C++ Question

Passing an array of objects to Member Function in c++

I use Turbo C++ and am experiencing an unexpected error in my code, please help..
I am trying to pass an array of objects to a member function.
An error : Undefined structure test , pops on the line where i define my print function

#include<iostream.h>
#include<conio.h>

class test
{
int t;
public:
void print(test T[])
{
cout<<"This Test\n";
}
};
void main()
{
clrscr();
test T1,T2[5];
T1.print(T2);
getch();
}


I have to use the outdated version of the Turbo C++ compiler at school so the syntax of the code might be different than the new compilers.

Answer

Define your function as void print(test *T).

Turbo C++ is broken in the regard of parameters of type test[] being equivalent to test*.

Comments