找回密码
 注册
查看: 527|回复: 1

模板相关的一个问题!

[复制链接]
发表于 2005-3-29 15:54:39 | 显示全部楼层 |阅读模式
//: test.h
#ifndef TEST_H
#define TEST_H
template< class T >
class Array {
    T A[ 10 ] ;
} ;
class abc {
} ;
#endif

//: main.cpp
#include "test.h"
int main() {
    Array< abc > l ;
}

对于模板中的
T A[ 10 ] ;
对象还不是照样会在栈中生成吗,因为没有使用new呀!
发表于 2005-4-5 17:29:16 | 显示全部楼层
是在栈中。模板是一种编译期的技术,所以有在编译时Aarray中的T会替换为类abc。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-9 01:47 , Processed in 0.022960 second(s), 15 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表