由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Does this function have memory problem?
相关主题
关于C++中一个Class的大小 (转载)reverse words, not the Microsoft one!!!
C++重载<<错误?about new operator
问个C++ virtual function的问题 (转载)C++里面
One c++ non-type template question两个继承问题
A try-catch problem in C++为什么我看不懂下面的code,是不是水平还不够?
a simple question for C++ classC++ 弱问一个
which func will be called?C++疑问
请问一个exception题目c++ 是否也有class method??
相关话题的讨论汇总
话题: does话题: function话题: cout话题: vector
进入Programming版参与讨论
1 (共1页)
c*********n
发帖数: 128
1
Does this function have memory problem?
void pushSomthingIntoVector(vector & v) { //T is a class
v.assign(0, T(100)) //T(int a) is a constructor of class T
v.push_back(T(50))
}
void anotherFunction() {
vector v;
pushSomethingIntoVector(v);
cout << v[0] << endl;
cout << v[1] << endl;
}
T(100) and T(50) are created locally within the function
pushSomthingIntoVector(vector & v), does it exsit outside of the function
? say, in the two lines of "cout" ?
Should I change the code as follows:
t****t
发帖数: 6806
2
all STL containers do copy in and copy out. you take care of all objects
outside the container, and the container will take care of the objects it
contains.

【在 c*********n 的大作中提到】
: Does this function have memory problem?
: void pushSomthingIntoVector(vector & v) { //T is a class
: v.assign(0, T(100)) //T(int a) is a constructor of class T
: v.push_back(T(50))
: }
: void anotherFunction() {
: vector v;
: pushSomethingIntoVector(v);
: cout << v[0] << endl;
: cout << v[1] << endl;

1 (共1页)
进入Programming版参与讨论
相关主题
c++ 是否也有class method??A try-catch problem in C++
two c++ interview questions! (转载)a simple question for C++ class
请教一个作用域的问题which func will be called?
c++ 得最基本问题请问一个exception题目
关于C++中一个Class的大小 (转载)reverse words, not the Microsoft one!!!
C++重载<<错误?about new operator
问个C++ virtual function的问题 (转载)C++里面
One c++ non-type template question两个继承问题
相关话题的讨论汇总
话题: does话题: function话题: cout话题: vector