inline.cpp

来自「ThinkingC++中文版」· C++ 代码 · 共 35 行

CPP
35
字号
//: C09:Inline.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Inlines inside classes
#include <iostream>
#include <string>
using namespace std;

class Point {
private:
	int i, j, k;
public:
    Point(): i(0), j(0), k(0)//default construct function
	{}
    Point(int ii, int jj, int kk): i(ii), j(jj), k(kk) 	//three parameters construct
	{}
	void print(const string& msg = "") const//with default argument const memeber function 
	{
		if(msg.size() != 0) 
			cout << msg << endl;
		cout << "i = " << i << ", " << "j = " << j << ", " << "k = " << k << endl;
	}
};

void main() 
{
	Point p, q(1,2,3);
    p.print("value of p");
    q.print("value of q");
} ///:~

//Here, the three constructors and the print( ) function are all inlines by default. 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?