我有这样的课:
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,我可以实现指针的无副本分配吗?谢谢各位专家!