I'm not fully familiar with templating but I need this to be inheritable and std::vector just spews warnings so I decided to just make my own mimicking it.
I'm getting this error: Error 4 error C2955: 'xsVector' : use of classtemplate requires template argument list c:\me\prjs\cpp\hackerex\hackerex2\hexdb_hack.h 101 1 hexDB
from this header file code:
xsDLL is defined from "hexDLL_zxStuff.h", it's for when I want it exported from a DLL which in this case is true. If there is something wrong with the way I did it then I would like to know now if possible. I'll add that headers code below. Edit: Just tried without and there was countless errors because I was trying to export code that otherwise
I want it inherited because it uses less bytes and is less of a pain to code for, as for specific type what do you think class xsDLL Hacks : public xsVector< Hack > is? I only omitted the rest of the class and the info about the Hack class, I thought the line was enough to show how I was using it but anyway thank you for clearing it up on that side of things.
There's a whole bunch of them so I figured it had something to do with how I created it or how I'm inheriting it, since it's all done the same way with the only thing being used is classes and numbers I figured only one was necessary.
For now while I wait I going to convert all my files to ANSI to stop VC from making incorrect complaints
The reason I need my own class is because I need it to be inherited into classes that are exported from DLLs, VC throws out a lot of complaints when I try this with std::vector<> so designing one from scratch that is intended to support exporting was the best solution I could come up with.
I also decided to use the same functions to avoid a need to document as there would already be usable documentation available.
To ensure that you do not violate ODR, what you have to do is simple; ensure that every component in the program (the executable and the dlls) use the same shared instance of the standard library. Build all of them to link with the the DLL version of the run-time library - either /MDd (debug) or /MD (release) . http://msdn.microsoft.com/en-us/library/2kzt1wy3(v=vs.100).aspx
For instance, this will work seamlessly if we build both with /MDd:
While I thank you for your reply, std::bad_alloc won't be an issue at the moment however I will take that into consideration. For reference I am also using wxWidgets so if I can avoid using the std namespace then I will (Which is why I used a different name altogether).
If you have a suggestion for the root class that can deal with such instances then I would be happy to hear it.
The way I understand it is that when you use a template your compiler sets up what my book called an "instance" of that template for each time you call that template using a different variable-type combination and that instance is held in memory until program end. So if you have a templated class that has several other classes that are derived from it then the compiler is going to make an instance for each variable type in each object and in each derived object type, so it can quickly use up a tonne of memory for even short codes. That's how I understand it at least.
template < typename T > T foo( const T& v )
std::vector<T> a ;
for( int i = 0 ; i < 1000 ; ++i ) a.push_back(v) ;
return a.front() ;
int i = 7 ;
double d = 0 ;
short s = 8 ;
float f = 3.4 ;
return foo<int>(7) /* + foo<double>(d) + foo<short>(s) + foo<float>(f) */ ;
This has one instantiation of std::vector<>.
Compile and build it with optimizations enabled ('Release' build in VS). Note the size of the executable.
Uncomment the commented part of line 17. return foo<int>(7) + foo<double>(d) + foo<short>(s) + foo<float>(f) ;
Now there are four instantiations of std::vector<>.
Compile, build, and check executable size as before.
That would give you a rough idea about the memory cost involved in the instantiation of std::vector<T>.
On your implementation, of course.