- 论坛徽章:
- 0
|
- #include <stdio.h>
- template<typename ITEM, int SIZE>
- class Array
- {
- public:
- class Item{
- public:
- Item(Array<ITEM, SIZE>& array) : _M_array(array) {
- array._M_size = SIZE;
- }
- void PrintSize()
- {
- printf("array item = %d\n", _M_array._M_size);
- }
- protected:
- Array<ITEM, SIZE>& _M_array;
- };
- public:
- int size() const;
- Item Get(int index);
- protected:
- ITEM _M_items[SIZE];
- int _M_size;
- };
- template<typename ITEM, int SIZE>
- inline int Array<ITEM, SIZE>::size() const { return SIZE;}
- template<typename ITEM, int SIZE>
- inline Array<ITEM, SIZE>::Item Array<ITEM, SIZE>::Get(int index) // 编译时这里总报:错误:expected initializer before ‘Array’
- {
- return Item(*this);
- }
复制代码 把报错的方法和类声明卸载一起是可以的,但分开就报错 |
|