#include <cstddef>
#include <iostream>
using namespace std;
template<class T, size_t N = 10> class Array {
T data[N];
size_t count;
public :
Array() {
count = 0;
}
void push_back(const T& t) {
if(count < N) {
data[count++] = t;
}
}
void pop_back() {
if(count > 0)
count--;
}
T* begin() {
return data;
}
T* end() {
return data+count;
}
};
template<class T, template<class, size_t = 10> class Seq>
class Container_2 {
Seq<T> seq;
public:
void append(const T& t) {
seq.push_back(t);
}
T* begin() {
return seq.begin();
}
T* end() {
return seq.end();
}
};
int mian() {
Container_2<int, Array> container;
container.append(1);
container.append(2);
int* p = container.begin();
while (p != container.end())
cout << *p++ << endl;
return 0;
}
这段代码是Thinking in c++ 第二卷中的一个例子,我看了N多遍了 编译不通过
提示如下:
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\ThinkInCpp\05\TempTemp3.o ..\src\ThinkInCpp\05\TempTemp3.cpp
Assembler messages:
Fatal error: can't create src\ThinkInCpp\05\TempTemp3.o: No such file or directory
Build error occurred, build is stopped
Time consumed: 3547 ms.