vector<primitive<> > - class question

Started by
9 comments, last by FXO 21 years, 8 months ago
While browsing throught FluidStudios collision detection algorithm, I found this:
  
"vector<primitive<> > &polygonList"
  
Its some kind of vector class with a specific pointertype, but Ive never seen it before (the <> stuff). And when i try to go to the definition of vector, it is located in "vector." which is not included in the source. Does anybody know how this works, how you can create a vector class and declare what kind of pointers it is to have like this? Thanks! /Fredrik Olsson Edit: the vector-line didnt show up correctly. [edited by - FXO on August 11, 2002 3:18:14 PM]
Advertisement
Never mind, after rebuilding everything, I could trace the function to "vc98\include\vector."
Look here, too:
http://www.sgi.com/tech/stl/Vector.html

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
That is called templates (or static meta programming).. and in my opinion is the most powerful tool in C++.

If brute force does not solve your problem....you''re not using enough!
If brute force does not solve your problem....you're not using enough!
Thanks, I have missed that completely.

Its a pity you cant typedef templates though.
Im thinking of using a #define ph_IntVec vector,
but that would be bad coding, #defines should be uppercase.
And upperchased PH_INTVEC defeats the purpose of having the type blend in with my other "ph_"-types.... maby im just to picky.

Thanks again
quote:Original post by FXO
Thanks, I have missed that completely.

Its a pity you cant typedef templates though.
Im thinking of using a #define ph_IntVec vector,
but that would be bad coding, #defines should be uppercase.
And upperchased PH_INTVEC defeats the purpose of having the type blend in with my other "ph_"-types.... maby im just to picky.

Thanks again



Yeah you can:

  typedef vector<int> IntegerVector;IntegerVector a; // a is of type vector<int>  




[edited by - fallenang3l on August 11, 2002 10:25:51 PM]
This is causing a lot of errors when i compile in debug mode:

    #ifdef _DEBUG	#define _CRTDBG_MAP_ALLOC	#include <stdlib.h>	#include <crtdbg.h>    #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)    #define new DEBUG_CLIENTBLOCK#endif#include <vector>  


Does anybody have a clue of what can be wrong?
The errors only occur when i #include <vector>.

Errors generated:

  octree.cppc:\program\microsoft visual studio\vc98\include\new(35) : error C2059: syntax error : 'constant'c:\program\microsoft visual studio\vc98\include\new(35) : error C2091: function returns functionc:\program\microsoft visual studio\vc98\include\new(35) : error C2809: 'operator new' has no formal parametersc:\program\microsoft visual studio\vc98\include\new(36) : error C2059: syntax error : 'constant'c:\program\microsoft visual studio\vc98\include\new(37) : error C2091: function returns functionc:\program\microsoft visual studio\vc98\include\new(37) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,const struct std::nothrow_t &)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl operator new(void))(unsigned int)'        c:\program\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'c:\program\microsoft visual studio\vc98\include\new(41) : error C2059: syntax error : 'constant'c:\program\microsoft visual studio\vc98\include\new(42) : error C2091: function returns functionc:\program\microsoft visual studio\vc98\include\new(42) : error C2556: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,void *)' : overloaded function differs only by return type from 'void *(__cdecl *__cdecl operator new(void))(unsigned int)'        c:\program\microsoft visual studio\vc98\include\new(35) : see declaration of 'new'c:\program\microsoft visual studio\vc98\include\new(42) : error C2809: 'operator new' has no formal parametersc:\program\microsoft visual studio\vc98\include\new(42) : error C2065: '_P' : undeclared identifierc:\program\microsoft visual studio\vc98\include\memory(16) : error C2059: syntax error : 'constant'c:\program\microsoft visual studio\vc98\include\memory(17) : error C2091: function returns functionc:\program\microsoft visual studio\vc98\include\memory(17) : error C2784: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' : could not deduce template argument for 'void *(__cdecl *)(unsigned int,class std::allocator<_Ty> &)' from 'void *(__cdecl *)(unsigned int)'c:\program\microsoft visual studio\vc98\include\memory(17) : error C2785: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' and 'void *(__cdecl *__cdecl operator new(void))(unsigned int)' have different return types        c:\program\microsoft visual studio\vc98\include\memory(16) : see declaration of 'new'c:\program\microsoft visual studio\vc98\include\memory(17) : error C2809: 'operator new' has no formal parametersc:\program\microsoft visual studio\vc98\include\memory(20) : error C2954: template definitions cannot nestError executing cl.exe.  


[edited by - FXO on August 11, 2002 11:52:53 PM]
I cant get the text to show up correctly, that sucks.
I don`t know if that is the problem.. but VC6 have some strange problems in using templates + precompiled headers. Disable precompiled headers.

If brute force does not solve your problem....you''re not using enough!
If brute force does not solve your problem....you're not using enough!
Trying to redefine new when using the standard library is a bit trouble-prone, mainly because it tends to redefine new too and things get mixed up. Firstly, try simply recompiling - sometimes when I get this error, it goes away if I just recompile the file. Illogical, but true. If that''s no good, try putting the #define after the #include, although it won''t catch the allocations in the library that way. It''s a shame that the whole debug new thing doesn''t work as documented.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

This topic is closed to new replies.

Advertisement