请解释一下两个语句的区别!谢谢!
vector<string> *pvec=new vector<string>(10,"hello");vector<string> *pvec=new vector<string>[10];
一个对象
vector<string> *pvec=new vector<string>[10];数组
具体的看看c++标准库 能不能说的再详细一点?我能不能这样理解:第一个语句分配了一个vector对象。该vector对象有10个值为"hello"的string对象。第二个语句是分配了10个vector对象的内存. 可以.... 第2句调用String的默认构造函数,所以初始化为空串。
这种问题,你该自己写个类,再构造函数里打印消息跟踪下,不就什么都明白了。 哦,谢谢!我暂时不会写类.我学了之后试一试。
页:
[1]
