Code design
Er? I'm not aware of anything preventing you from using an explicit constructor in an initialization list? The items of the list are basically (explicit) constructor calls, aren't they?
@ToohrVyK:
Thanks for your great help(its not the first time , lol).
I think im ready to start cleaning up this mess.
Quote:
Also, apply a hash function to your strings to make it faster to handle than plain old strings
I was going to use std::hash_map , but for some reason all the stl headers
that i downloaded , simply , messed up the compiler(code blocks),so
i decided to use std::map , and SDBM hash function.
Just now , i did a quick search and i found this
site:
http://marknelson.us/2007/08/01/memoization/
Which explains how std::hash_map can be used on gcc compilers.
I think i'll go with hash maps for all resources..
Quote:Original post by Zahlman
Er? I'm not aware of anything preventing you from using an explicit constructor in an initialization list? The items of the list are basically (explicit) constructor calls, aren't they?
There is nothing preventing you from doing so generally.
The Config object isn't a member attribute, as it's only needed in the constructor, so it cannot be used in the initialisation list. If you want the Engine constructible from a filename string then either the Config needs an implicit constructor or one needs instantiating after the initialiser list - neither is option particularly creamy.
Quote:Original post by 3Dgonewild
I was going to use std::hash_map , but for some reason all the stl headers
that i downloaded , simply , messed up the compiler(code blocks),so
i decided to use std::map , and SDBM hash function.
To clarify, hash_map isn't in the standard C++ library. I know that SGI have one in their STL implementation though, which leads to continuous confusion with people thinking it is there as standard.
@dmatter:
Hmm..so , should i implement something on my own with std::map & a custom hash function?
Something like that:
Quote:
To clarify, hash_map isn't in the standard C++ library.
I know that SGI have one in their STL implementation though,
which leads to continuous confusion with people thinking it is there as standard.
Hmm..so , should i implement something on my own with std::map & a custom hash function?
Something like that:
Texture cache - example - :class Texture{ public: Texture(const unsigned int udata,const unsigned int tid,const int tw,const int th) :data(tdata),hashedID(tid),w(tw),h(th){} unsigned int data,hashedID; int w,h;}; //id(hash) //texturestd::map<unsigned int,Texture> textures;addResouce-Texture(const std string& name,const std::string& file){Texture t(.....); map.add<make pair buildHash(name) , t)}call texture(const std string& name){ unsigned int id = buildHash(name) map.find(id) bind / etc..}
Quote:Original post by 3Dgonewild
should i implement something on my own with std::map & a custom hash function?
No need, boost already does this for you.
Quote:Original post by Zahlman
Er? I'm not aware of anything preventing you from using an explicit constructor in an initialization list? The items of the list are basically (explicit) constructor calls, aren't they?
Consider this code:
Engine::Engine(const Config &conf) : renderer(conf), resources(conf), playlist(conf) {}Engine engine(Config("filename"));
How can you rewrite this function so that Config does not have an implicit constructor, yet the following code is equivalent to the code above in terms of functionality?
Engine engine("filename"));
In terms of OCaml, I'm saying that C++ does not support this:
class engine(filename) = let config = new config(filename) in object val renderer = new renderer(config) val resources = new resources(config) val playlist = new playlist(config) end
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement