c++ 为什么输出的是垃圾值?

#include<iostream.h> #include<math.h> class student{ friend class teacher; private:int id,clas; int math,physics; public: student(int id,int clas,int math,int physics) { id=id; clas=clas; math=math; physics=physics; } }; class teacher{ public : int sum1; teacher(student &a,student &b){ if(a.clas==1){ sum1+=a.math; } if(b.clas==1){ sum1+=b.math; } cout<<sum1<<endl; } }; voi

第1个回答  2014-10-30
id=id; clas=clas; math=math; physics=physics;

这里改一下:
this->id=id;
this->clas=clas;
this->math=math;
this->physics=physics;追问

error C2228: left of '.id' must have class/struct/union type

追答

你的代码没有贴完整?

本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网