So I am working on a software based 3d engine. I have a structure called triangle, and a class called object. The object class contains an array of triangles that make up that object, and position/orientation data.
Anyway, I am writing a function called createCube, which is supposed to return an instance of object (or a pointer to an instance of object). The returned object will contain a bunch of triangles that together resemble a cube (duh). Anyway, Im having some difficulty writing this function. This is what I have, minus the irrelevant parts:
This does not compile. It says "conversion from 'object*' to nonscalar type 'object' requested" on the line "object theCube= new obj...." So I added a couple astericks (*), changing it to:Code:object createCube(int xpos, ..... ) { triangle theTriangles[12]; //..... //code to set triangles to form cube //...... object theCube = new object(xpos, ypos, zpos,0,0,0); for (int i=0;i<12;i++) { theCube.addTriangle(theTriangles[i]); } return theCube; }
But now, it finds a problem with the line "theCube.addTriangle(....)" It says that addTriangle has not been declared (it has) and that their is a request for member of non-aggregate type before '(' token. I tried putting a '&' in front of that line, but it didn't help.Code:object* createCube(int xpos, ..... ) { triangle theTriangles[12]; //..... //code to set triangles to form cube //...... object* theCube = new object(xpos, ypos, zpos,0,0,0); for (int i=0;i<12;i++) { theCube.addTriangle(theTriangles[i]); } return theCube; }
I know the problem has something to do with pointers and reference and dereference operators or something like that. I know its sad that I can figure out 3d math, but not simple classes and pointers. Can anyone help me out? It would be greatly appreciated.
Thanks!



). No, of course, when you use a local object like that, the constructor is being called too.