question about function friend(help)

godofwar47's Avatar
Banned
hi guys .i am beginner .plz tell me why is my program problem?plz write answer my question.tnx
Code:
#include <iostream>
using namespace std;
class test1{
int x;
int y;
public:
void set_xy(int i,int j){x=i;y=j;}
 friend int equal (test1 t1 ,test2 t2);
};
class test2 {
int x;
int y;
public:
void set_xy (int i,int j) {x=i;y=j;}
friend int equal (test1 t1,test2 t2);
};
int equal(test1 t1,test2 t2);
{if (t1.x==t2.x  &&  t1.y==t2.y)
return 1;
else 
return 0;}
int main()
{
test1 t1;
test2 t2;
t1.set_xy(3,5)
t2.set_xy(4,5)
if (equal(t1,t2))
cout<<"t1 and t2 are equal"<<endl;
return 0;
}

Last edited by shabbir; 3Jan2011 at 11:26.. Reason: Code blocks
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You had the same thread 2 more times which I have deleted and avoid doing that.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
The semicolon after equal() completes the definition of a prototype, so the code afterwards is incorrect because there's no function header. Remove the semicolon and that should fix the problem.