I am using many stl containers in my projects, most of them only contain pointers but to different class objects. For example
Code: Select all
std::vector<Prop*>
std::vector<Shape*>
std::map<string,Prop*>
std::map<string,Player*>
I am using VS2008
Code: Select all
std::vector<Prop*>
std::vector<Shape*>
std::map<string,Prop*>
std::map<string,Player*>
tod wrote:Templates get expanded by the preprocessor. This means vector<int> and vector<float> will actually generate two classes that offer the vector functionality, one for int and one for float. Of course you could do this yourselfBut with more work, less speed and more bugs.
Code: Select all
vector<int *> nodes;
nodes.push_back((int*) mySceneNodePtr);
Got it.The preprocessor has nothing to do with templates; it doesn't have enough information to do such a sort of thing. Templates are handled by the compiler itself.
This is a very good question. You can use the debugger to find out.Pangamini wrote:Hello there
I am using many stl containers in my projects, most of them only contain pointers but to different class objects. For exampleIn the example, how many templates are compiled? 2 or 4?Code: Select all
std::vector<Prop*> std::vector<Shape*> std::map<string,Prop*> std::map<string,Player*>
I am using VS2008
Code: Select all
std::vector<void*> v;
v.push_back((void*) new int());
v.push_back((void*) new class_name());
Why would you want to reduce it? I can't imagine it would be causing you any problems whatsoever.Pangamini wrote:Is there any way how to reduce it? Since the output code will be exactly the same...
I think what he wants is same STL code for all stl pointers ie std::vector<whateverpointer> will point to one source code since the logic thinking is pointer is always 32 or 64 bit.betajaen wrote:Personally, it seems rather silly to me.
Code: Select all
std::vector<void*> v; v.push_back((void*) new int()); v.push_back((void*) new class_name());
Code: Select all
std::vector<int*> a;
std::vector<myclass*> b;
std::vector<float*> c;