Sign in to follow this  
Ashaira

Getting error C2819. Need some help.

Recommended Posts

Ashaira    105
Well ive been working on a small game engine in OpenGL ES 2.0 and until today everything was fine. Today i decided to put my Scene Manager and Resource Manager clases as extern in a globals.h and declare them in the init in the main.cpp. After doing so i keep getting error C2819 for variable that until recently worked fine.

For example in the Scene Manager i have a pointer that holds all the objects declared as such
[code]CGameObject * GameObjects;[/code]

And then use it in the cpp in various places. one example where i get the error is here
[code]if(GameObjects[i]->shader == j+1)[/code]

as far as i understand this error can appear when using the -> operator on non pointer types but GameObjects is a pointer.

Could anyone help me?

If posting the whole files will help you understand better let me know.

EDIT: upon further investigation the cause seems to be the use of STL. i used STL to read from files and now since i turned the SM and RM into global extern it seem STL is overwriting some pointer operators. Could someone tell me how to block this overwrite? ide like to keep using the file reading i implemented if possible if not could someone point me towards some file reading that doesnt use the STL? all the examples i have found so far use STL.

Share this post


Link to post
Share on other sites
mrjones    612
I doubt this is STL problem. Perhaps I'm wrong, but it seems to me that accessing GameObjects[i] gives you a GameObject instance that is not a pointer. So this should be correct instead:
[code]
if(GameObjects[i].shader == j+1) ...
[/code]
In short, GameObjects is a pointer in your code, but GameObjects[i] is not:
[code]
CGameObject * GameObjects; // Pointer to GameObject instances
// ...
// Initialize GameObjects etc
// ...
GameObject& go=GameObjects[i]; // go is reference to GameObject, not a pointer
[/code]
This would give you a pointer at i:
[code]
CGameObject ** GameObjects; // Pointer to pointers of GameObject instances
// ...
// Initialize GameObjects etc
// ...
GameObject* go=GameObjects[i]; // go is pointer to GameObject
[/code]

Note: all the above is assuming that CGameObject is a class, not a pointer type.

Share this post


Link to post
Share on other sites
Ashaira    105
Oh thnx. i looked at it again ur right.
GameObjects
Was initialy an array of pointers so my refrence lvl was off. stupid me. thnx.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this