【发布时间】:2011-04-16 10:59:39
【问题描述】:
我有这样的课:
class largeInt{
vector<int> myVector;
largeInt operator* (const largeInt &arg);
}
在我的主要工作中,我在使用指针时无法避免复制:
void main(){
//this works but there are multiple copies: I return a copy of the calculated
//largeInt from the multiplication and then i create a new largeInt from that copy.
largeInt testNum = 10;
largeInt *pNum = new HugeInt( testNum*10);
//i think this code avoid one copy but at the end hI points to a largeInt that has
// myVector = 0 (seems to be a new instance = 0 ). With simple ints this works great.
largeInt i = 10;
largeInt *hI;
hI = &(i*10);
}
我认为我在矢量设计中缺少/没有管理某些东西.. 我可以实现指针的无副本分配,即使没有实例化一个新的 largeInt? 谢谢各位专家!
【问题讨论】:
标签: c++ pointers vector copy bigint