内联成员函数 内联成员函数
inline + 成员函数
整个函数体出现在类定义内部
class B{ inline void func1(); void func2() { }; }; void B::func1() { }
重载成员函数 成员函数 -- 带缺省参数 3 #includeusing namespace std; class Location { private : int x, y; public: void init( int x=0 , int y = 0 ); void valueX( int val ) { x = val ; } int valueX() { return x; } };
void Location::init( int X, int Y){ x = X; y = Y; } int main() { Location A; A.init(5); A.valueX(5); cout << A.valueX();
return 0; }
使用缺省参数要注意避免有函数重载时的二义性 class Location { private: int x, y; public: void init( int x =0, int y = 0 ); void valueX( int val = 0 ) { x = val; } int valueX() { return x; } }; Location A; A.valueX(); //错误, 编译器无法判断调用哪个valueX
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.