网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C/C++
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.用Delphi实现图像放大镜.
.BCB的命令行参数.
.Turbo C下的寄存器变量.
.通用ShellCode深入剖析.
.在CB5中使用ADO数据库编程.
.C的学习方法.
.C语言编程常见问题解答之常用函数.
.虚拟文件系统.
.如何实现在一个Dbgrid中显示多数.
.钩子的应用: 程序运行监视.
.为C++标准库容器写自己的内存分配.
.在Win9x/NT下获取硬盘物理序列号.
.Visual C++6.0 API函数操作技巧集.
.新手入门:C++中布尔类型.
.对C++中引用的补充说明(实例).
.内存调试技巧:C 语言最大难点揭.
.在桌面上画图.
.局部类和嵌套类.
.创建可移植的64位应用程序代码.
.c语言最经典的链表.

Another way to handle array initialization

发表日期:2008-3-8



  PROBLEM: bwh@kato.prl.ufl.edu (Brian Hook)

[...]

I STILL haven't gotten a good technical reason why
parameters to constrUCtors for arrays haven't been at least talked out (I'm
not a committee member, so I don't know if this has been shot down
informally, so if it has, forgive my lack of knowledge on this).

I even asked The Man himself, and his response was basically that he didn't
see much need for it. I know I run into instances on occasion where I want
to specify something that is constant over an entire array of objects. For
example, something even as simple as "name".

Object array1[100]("Member of array1");
Object array2[100]("Member of array2");

I suppose templates serve much the same purpose, but it just seems so
damned inconsistent to not have parameters to constructors for arrays!

Sure, there's the old trick:

Object::name = "Member of array1";
Object array[100];
Object::name = "Member of array2";
etc. etc.

Now if THAT ain't ugly, I don't know what is!


RESPONSE: kanze@us-es.sel.de (James Kanze), 6 Jul 94

The trick I use is slightly different:

template< double r , double i >
class ComplexWithInit : public Complex
{
public :
ComplexWithInit()
: Complex( r , i ) {}
} ;

Complex* c1 = new ComplexWithInit< 1.0 , 2.0 >[ 10 ] ;
Complex* c2 = new ComplexWithInit< 3.0 , 4.0 >[ 20 ] ;

Formally speaking, this is *not* guaranteed to work. Practically, I
would be interested in hearing about a plausible implementation where
it will not actually work. (Finding the correct standardese which
would permit guaranteeing this to work without causing problems
elsewhere is a non-trivial problem, however.)
上一篇:51单片机Keil C延时程序的简单研究 人气:1731
下一篇:API之菜单函数 人气:761
浏览全部C/C++的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐