I'm curious as to why the following code doesn't work. In particular, the compiler seems to be viewing *(result + i) as a gVector3 type as opposed to a float. But result is a pointer to a float array right? So wouldn't dereferencing a pointer return a float? You can assume that gVector3 and gMatrix3 are defined.
/* returns the column vector at index i */
gVector3 gMatrix3::getColumn(unsigned int index) const{
gVector3* result = new gVector3();
for (int i = 0; i < 3; i++){
*(result + i) = data[i][index];
}
return *result;
}
If gVector3 is a class, then it probably overloads operator[]
, which is what you should use. Otherwise you're performing pointer arithmetic on the object itself. Try this:
(*result)[i] = data[i][index];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.