0

Possible Duplicate:
Is there a way to instantiate objects from a string holding their class name?

I've written a Vbo template class to work with vertex buffer objects in opengl. I'm writing for multiple platforms in c++.

I'd like to set the type from a config file at runtime.

e.g.

<vbo type="bump_vt" ... />

Vbo* pVbo = new Vbo<bump_vt>(...);

Is there some way I can do this without a large if else block e.g.

 Vbo* pVbo;

if( sType.compareTo("bump_vt") == 0 )
    pVbo = new Vbo<bump_vt>(...);
else if
    ...

thanks

Community
  • 1
  • 1
fishfood
  • 4,092
  • 4
  • 28
  • 35

1 Answers1

2

C++ doesn't allow that, because types are resolved during compilation.

But you may use std::map to simplify the process.

mexus
  • 990
  • 6
  • 6