[C++] 内联函数_计算正方形的面积及周长 →→→→→进入此内容的聊天室

来自 , 2020-12-10, 写在 C++, 查看 103 次.
URL http://www.code666.cn/view/f22e4747
  1. #include "stdafx.h"
  2. #include "iostream"
  3. using namespace std;
  4. class Square
  5. {
  6. private:
  7.         double length;
  8. public:
  9.         Square(double x);
  10.         void area()//函数体内定义,默认为内联函数(成员函数设置为 内联函数的第一种方式)
  11.         {
  12.                 cout << "正方形的面积为:" << length*length << endl;
  13.         }
  14.         inline void Perimeter();//在类内进行内联函数声明
  15. };
  16. Square::Square(double x)
  17. {
  18.         length = x;
  19. }
  20. void Square::Perimeter()//在类外给出内联函数定义
  21. {
  22.         cout << "正方形的周长:" << 4 * length << endl;
  23. }
  24. void main()
  25. {
  26.         Square ss(2.0);
  27.         ss.area();
  28.         ss.Perimeter();
  29. }
  30. //2014年4月22日20:34:36    从开始写到修改完大概用了30分钟,很伤- -。
  31. //30行
  32. //修改了N长时间
  33. //错误1: 申明一个类之后直接{},不用加()
  34. //错误2: 在类内进行内联函数申明时指定为void返回值,类外说明是忘记定义返回值了,默认为int型,所以冲突
  35. //错误3: 类声明完成之后记得加;

回复 "内联函数_计算正方形的面积及周长"

这儿你可以回复上面这条便签

captcha