对于一个很短的程序,内联函数是不是意义不大? 它的作用是不是可以缩短时间节约时间和内存?
#include<iostream>
using namespace std;
class point{
public:
point(int xx = 0, int yy = 0); { X = xx ; Y = yy ; }
point(point & p );
int getx() {return X;}
int gety() {return Y;}
private:
int X , Y;
};
point::point(int xx = 0, int yy = 0)
{
X = xx ; Y = yy ;
}
point::point(point & p)
{
X = p.X;
Y = p.Y;
}
void fun1(point p)
{
cout<<p.getx()<<endl;
}
point fun2( )
{
point A(1,2);
return A;
}
int main()
{
point A(4,5);
point B(A);
cout<<B.getx()<<endl;
fun1(B);
B = fun2();
cout<< B.getx()<< endl;
}
上面这个函数中的下划线部分,内联函数和不用内联函数在外部定义,差别就不大了?