#include "stdafx.h" |
#include "iostream" |
using namespace std; |
class Square |
{ |
private : |
double length; |
public : |
Square( double x); |
void area() //函数体内定义,默认为内联函数(成员函数设置为 内联函数的第一种方式) |
{ |
cout << "正方形的面积为:" << length*length << endl; |
} |
inline void Perimeter(); //在类内进行内联函数声明 |
}; |
Square::Square( double x) |
{ |
length = x; |
} |
void Square::Perimeter() //在类外给出内联函数定义 |
{ |
cout << "正方形的周长:" << 4 * length << endl; |
} |
void main() |
{ |
Square ss(2.0); |
ss.area(); |
ss.Perimeter(); |
} |
//2014年4月22日20:34:36 从开始写到修改完大概用了30分钟,很伤- -。 |
//30行 |
//修改了N长时间 |
//错误1: 申明一个类之后直接{},不用加() |
//错误2: 在类内进行内联函数申明时指定为void返回值,类外说明是忘记定义返回值了,默认为int型,所以冲突 |
//错误3: 类声明完成之后记得加; |