[C++] 纯文本查看 复制代码 template<typename T>
class MyArray
{
public:
MyArray(const size_t& Length)
{
this->Value = new T*[Length];
return;
}
void push(const T& obj) {
T* pNOBJ = new T(obj);
Value[s++] = pNOBJ;
}
void pop() {
if(s > 0)
s--;
}
T& top() {
return *Value[s - 1];
}
size_t size() {
return s;
}
private:
T** Value;
size_t s = 0;
};
class Test
{
public:
Test(int Arg)
{
this->Value = Arg;
}
int Value;
};
int main()
{
MyArray<Test> a(200);
Test b(1);
a.push(b);
for (int i = 0; i < 20; i++) {
a.push(Test(i));
}
for (;a.size();) {
cout << a.top().Value << " ";
a.pop();
}
}
另外vector也不能work gcc 6.3.0 |