求问程序中result哪里出错了
#include<iostream>#include<cmath>
using namespace std;
class TestClass1
{
friend class Testclass2;
public:
//********2********
TestClass1(float a,float b)
{
X=a;
Y=b;
}
TestClass1(float a)
{
X=a;
Y=0;
}
void print()
{
cout<<"x="<<X<<endl;
cout<<"y="<<Y<<endl;
}
private:
float X,Y;
};
class TestClass2
{
public:
float Distance(TestClass1& p,TestClass1& q);
};
float TestClass2::Distance(TestClass1& p,TestClass1& q)
{
float result;
result=sqrt((p.X-q.X)*{p.X-q.X)+(p.Y-q.Y)(p.Y-q,Y); // error C2248: 'X' : cannot access private member declared in class 'TestClass1'
cout<<result<<endl;
return result;
}
int main()
{
TestClass1 p(10,10),q(20);
TestClass2 d;
d.Distance(p,q);
return 0;
}