![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |
| |||
| Arrays are never copied, but passed by pointer, so the compiler is complaining that you're returning a pointer, but the return type is an array type. Ultimately its preventing you from doing something which would cause undefined behaviour, like a crash or a seg fault. Your function would be returning a pointer to some memory which is allocated in your function, and therefore it will be deallocated as soon as your function returns. Depending whether you're using C++ or not, the preferred alternative is to use an STL container such as vector, which may be copied any way you like. If you haven't got the STL containers available, then you should create your array externally from the function, and pass it in as an argument - allowing the function to modify an existing array, rather than attempting to return a whole new array from a function. There are other alternatives, such as creating the array dynamically (Bad solution - its open to all kinds of memory management nightmares), or wrapping the array in a struct (worth considering, if you can justify turning Vec3 into a struct type - struct objects may be copied in full, so can be used as return types for a function) |
| |||
| If your using C++. Just create a class like this class Vec3 { union { float xyz; struct { float x, y, z; }; }; MATH_INLINE void glNormal3d(Vec3& p1, Vec3& p2) { Vec3 v = Vec3(x, y, z); Vec3 v1 = p1 - v; Vec3 v2 = p2 - p1; Vec3 normal = Vec3(v1.cross(v2)); normal.normalise(); normal.printVec3(); glNormal3dv(normal.ptr()); } }; EDIT: Sorry theres no way to delete the post. Just noticed its 3 months old. Last edited by Eckos : 06-17-2008 at 03:48 PM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |