Hey gamedev,I am extremely rusty with my C++ skills. I want to pass my camera object to the terrain class, so I can cull some subgrids from my view frustrum.So, my initial idea was to pass the camera in the terrain constructor.I have my camera declared like this:

Camera g_Camera;

and after I initialize the camera I call the constructor for my terrain.I am really unsure how I should accomplish this, but I would save a "Camera &" in my terrain class and just pass over the reference in the constructor. But I get these errors:

References must be initialized when defined, however this doesn't work for non-static members, thus you must initialize the reference in the class initializer list.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.ScapeCode - Blog | SlimDX

Well, seeing as how you havent really posted much code, I can't tell you what's wrong. Although the error messages do suggest that it doesn't know what a "Camera" is, perhaps you're missing a header include.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.ScapeCode - Blog | SlimDX

You didn't include camera in your terain.cpp. The definition of the incomplete type of Camera is required by then.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.ScapeCode - Blog | SlimDX

You didn't include camera in your terain.cpp. The definition of the incomplete type of Camera is required by then.

I don't need to include the camera because of the forward declaration: terrain is not a parent of camera and it does not contain a camera object, but a reference.Nevertheless, I switched to '#include "Camera.h"' and I get the exact same error.

You need the definition of the camera class at the time of construction because incomplete types (which is what a forward decleration is) cannot be constructed.

Regardless of that, this line:

g_Camera = cam;

Is incorrect.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.ScapeCode - Blog | SlimDX

Without seeing the code here, I can't tell you exactly what's going on here, however it basically is just telling you that it has no idea what mCamera is, its not encountered it within the current name scope. The code you pasted is, pretty much, useless.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.ScapeCode - Blog | SlimDX

mCamera is a reference, not a pointer. You don't use -> to access the members of a reference.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.ScapeCode - Blog | SlimDX

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.ScapeCode - Blog | SlimDX

I've looked into it before and I am still clueless.SubGrid does not know mCamera. Using Terrain::mCamera does not work. Making mCamera static also. :/ Thanks for your help, though.It says: "Camera & Terrain::mCamera Error: a nonstatic member reference must be relative to a specific object"But this gets called after the constructor where I pass the specific object (the reference) to mCamera. I'm clueless.

I would highly recommend learning the language before you start too far down the road with your game. Especially when your solution to problems is "damn, I don't understand why this is illegal, I'll just make it a global."

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.ScapeCode - Blog | SlimDX

Your SubGrid type is an inner class of Terrain. However, it has no relationship with the parent class. That is, a SubGrid isn't associated with any particular Terrain instance. One solution is to put a pointer to Terrain in the SubGrid (intiialised in the constructor). The operator<() can use this pointer to access the camera.

As Washu correctly points out - this is a basic language issue.

Well I took out everything that is not part of the problem.

No, there is still a huge amount of code in that that is nothing to do with the problem. This is what the code would look like if you had taken everything out:

This code distils the essence of your problem - it should generate exactly the error you were looking at.

Also note that the code dump you gave is not properly indented, which makes it very difficult to decipher. Once again, having less code would make this less of an issue.

As an aside, it is usually a good idea to not use references as members. References have strange semantics as members because they are not reseatable. Instead, convert the reference to a pointer. The constructor can still take a reference, which neatly documents the intent of the class.

Your SubGrid type is an inner class of Terrain. However, it has no relationship with the parent class. That is, a SubGrid isn't associated with any particular Terrain instance. One solution is to put a pointer to Terrain in the SubGrid (intiialised in the constructor). The operator<() can use this pointer to access the camera.

As Washu correctly points out - this is a basic language issue.

Well I took out everything that is not part of the problem.

No, there is still a huge amount of code in that that is nothing to do with the problem. This is what the code would look like if you had taken everything out:

This code distils the essence of your problem - it should generate exactly the error you were looking at.

Also note that the code dump you gave is not properly indented, which makes it very difficult to decipher. Once again, having less code would make this less of an issue.

As an aside, it is usually a good idea to not use references as members. References have strange semantics as members because they are not reseatable. Instead, convert the reference to a pointer. The constructor can still take a reference, which neatly documents the intent of the class.