Note that there are some explanatory texts on larger screens.

plurals
  1. POUse global variables as parameters of a function allocated in other source file
    primarykey
    data
    text
    <p>I'm coding a program of openGL which read the points and the faces from a text file and later displays them on the screen.</p> <p>I do the opengl matters in main.cpp and I load the file in LoadFile.cpp.</p> <p>In the main, I have an array with the points that I'm going to display:<br/></p> <pre><code> Point3f* vertexContainer; int vertexn; </code></pre> <p>And I've declared the function that I'm going to use in order to load the source file:<br/></p> <pre><code>extern void loadFile(const char*,Point3f*, int, Face*, int); </code></pre> <p><i>Note that extern is not mandatory here. Don't care about faces, for the momment.</i></p> <p>Inside LoadFile.cpp:<br/></p> <pre><code>void loadFile(const char* path, Point3f* vertexContainer, int nvertex, Face* faceContainer, int nfaces) { //reading and processing source file, //storing the input vertices in: std::vector&lt;Point3f&gt; verticesVector. //Finally: vertexContainer = &amp;verticesVector[0]; vertexn = verticesVector.size(); } </code></pre> <p>And nothing is displayed on the screen. Also, If I debug vertexContainer, I realize that its value never changes.</p> <p>However, if I debug a local variable vc, I can see the changes:<br/></p> <pre><code>Point3f* vc = &amp;verticesVector[0]; </code></pre> <p>I have noticed that, if i pass by reference the array, it changes, but, mysteriously when the program control comes back to main, its values have changed wrongly!<br/> And I had thought that arrays never have to be passed by reference.</p> <p>The other approach is return the vector itself to the main, but prefer be able to work with arrays, once the file is processed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload