15_2_2.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //15_2_2
  2. #include <iostream.h>
  3. class Animal;
  4. void SetValue(Animal&, int);
  5. void SetValue(Animal&, int, int);
  6. class Animal{
  7. public:
  8.   void Set(int v);
  9.   void Set(int v, int w);
  10. protected:
  11.   int itsWeight;
  12.   int itsAge;
  13. };
  14. void Animal::Set(int v){ itsWeight = v; }
  15. void Animal::Set(int v, int w){ itsWeight=v; itsAge=w; }
  16. void SetValue(Animal& ta, int tw){ ta.Set(tw); }
  17. void SetValue(Animal& ta, int tw, int tn){ ta.Set(tw,tn); }
  18. void main()
  19. {
  20.   Animal peppy;
  21.   SetValue(peppy, 5);
  22.   SetValue(peppy,7,9);
  23. }