0

I have an OpenGL application which requires the use of a vector in more than one OpenGL function. As far as I know the best way of dealing with this is to declare the vector in a header file, and include the header file in all the files containing the OpenGL functions.

The problem is that I get a multiple definition error at the linker stage. What is the best solution to this? Is there a better way of doing it without globals?

datenwolf
  • 159,371
  • 13
  • 185
  • 298
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225

2 Answers2

0

Define your vector in one of the implementation files and declare it as extern in rest of the places where it's needed or in header file.

In most cases globals are not the way to go, but without having a look at the overall design no one can tell for sure what's the best for your situation.

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85
-3

the other way is to use Singleton pattern

vurtne.ye
  • 141
  • 3