【发布时间】:2013-11-24 00:38:41
【问题描述】:
为了具体化我的问题,我使用了具有以下定义的 Matrix 类:
Matrix(unsigned int, unsigned int); // matrix of the given dimension full of zeroes
Matrix(Matrix*); // creates a new matrix from another one
int &operator()(int, int); // used to access the matrix
int **matrix; // the matrix
现在取这两个代码sn-ps:
第一:
Matrix test(4,4);
Matrix ptr = test;
ptr(0,0) = 95;
第二:
Matrix test(4,4);
Matrix *ptr = &test;
(*ptr)(0,0) = 95;
两个代码的效果一样,(0,0)位置的元素得到95(第一个sn-p和Java很像,所以才问这个问题的原因)。 问题是,这两种方法都正确地分配了对象吗?
【问题讨论】:
-
我想你会发现它们并不相同......
标签: c++ object variable-assignment assign