stemp2.cpp

来自「Think in C++ 第二版源码」· C++ 代码 · 共 28 行

CPP
28
字号
//: C16:Stemp2.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// Non-inline template example

#include "../require.h"



template<class T>

class Array {

  static const int size = 100;

  T A[size];

public:

  T& operator[](int index);

};



template<class T>

T& Array<T>::operator[](int index) {

  require(index >= 0 && index < size,

    "Index out of range");

  return A[index];

}



int main() {

  Array<float> fa;

  fa[0] = 1.414;

} ///:~

⌨️ 快捷键说明

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