1、内联函数:
在函数声明处定义,即在类头文件中定义内联函数,在函数定义处添加inline关键字编译不通过:
如
//A.h文件
class A
{
public:
inline int Add(int nLeft,int nRight)
{
return nLeft + nRight;
}
};
inline int A::Add(int nLeft,int nRight)
{
return nLeft + nRight;
}
2、函数的const:
在函数声明处结尾加上const,在函数定义处也需要加上const
//A.h文件
class A
{
public:
int GetResult()const;
private:
int result;
};
//A.cpp文件
int A::GetResult()const
{
return result;
}