Search Results

Search found 10 results on 1 pages for 'smerlin'.

Page 1/1 | 1 

  • Why is casting Derived** to Base*const* forbidden ?

    - by smerlin
    After reading this question, i saw the answer by Naveen containing a link to this page, which basically says, that casting from Derived** to Base** is forbidden since could change a pointer to an pointer to a Derived1 object point to a pointer to a Derived2 object (like: *derived1PtrPtr=derived2Ptr). OK, i understand this is evil ... But when casting Derived** to Base*const* this is not even possible, so whats the reason that this is not allowed anyway ?

    Read the article

  • Is it possible to create your own custom locale

    - by smerlin
    Since Windows doesnt have a C++ locale with UTF8 support by default, i would like to construct a custom locale object which supports UTF8 (by creating it with a custom ctype facet). How can i construct a locale object with a my own ctype implementation (i only found functions to construct a locale using an already existing locale as base..) If C++ does not support construction of locales with a custom ctype facet at all, why is that so ?

    Read the article

  • (static initialization order?!) problems with factory pattern

    - by smerlin
    Why does following code raise an exception (in createObjects call to map::at) alternativly the code (and its output) can be viewed here intererestingly the code works as expected if the commented lines are uncommented with both microsoft and gcc compiler (see here), this even works with initMap as ordinary static variable instead of static getter. The only reason for this i can think of is that the order of initialization of the static registerHelper_ object (factory_helper_)and the std::map object (initMap) are wrong, however i cant see how that could happen, because the map object is constructed on first usage and thats in factory_helper_ constructor, so everything should be alright shouldnt it ? I am even more suprised that those doNothing() lines fix the issue, because that call to doNothing() would happen after the critical section (which currently fails) is passed anyway. EDIT: debugging showed, that without the call to factory_helper_.doNothing(), the constructor of factory_helper_ is never called. #include <iostream> #include <string> #include <map> #define FACTORY_CLASS(classtype) \ extern const char classtype##_name_[] = #classtype; \ class classtype : FactoryBase<classtype,classtype##_name_> namespace detail_ { class registerHelperBase { public: registerHelperBase(){} protected: static std::map<std::string, void * (*)(void)>& getInitMap() { static std::map<std::string, void * (*)(void)>* initMap = 0; if(!initMap) initMap= new std::map<std::string, void * (*)(void)>(); return *initMap; } }; template<class TParent, const char* ClassName> class registerHelper_ : registerHelperBase { static registerHelper_ help_; public: //void doNothing(){} registerHelper_(){ getInitMap()[std::string(ClassName)]=&TParent::factory_init_; } }; template<class TParent, const char* ClassName> registerHelper_<TParent,ClassName> registerHelper_<TParent,ClassName>::help_; } class Factory : detail_::registerHelperBase { private: Factory(); public: static void* createObject(const std::string& objclassname) { return getInitMap().at(objclassname)(); } }; template <class TClass, const char* ClassName> class FactoryBase { private: static detail_::registerHelper_<FactoryBase<TClass,ClassName>,ClassName> factory_helper_; static void* factory_init_(){ return new TClass();} public: friend class detail_::registerHelper_<FactoryBase<TClass,ClassName>,ClassName>; FactoryBase(){ //factory_helper_.doNothing(); } virtual ~FactoryBase(){}; }; template <class TClass, const char* ClassName> detail_::registerHelper_<FactoryBase<TClass,ClassName>,ClassName> FactoryBase<TClass,ClassName>::factory_helper_; FACTORY_CLASS(Test) { public: Test(){} }; int main(int argc, char** argv) { try { Test* test = (Test*) Factory::createObject("Test"); } catch(const std::exception& ex) { std::cerr << "caught std::exception: "<< ex.what() << std::endl; } #ifdef _MSC_VER system("pause"); #endif return 0; }

    Read the article

  • how to get the type of a deferred template parameter

    - by smerlin
    Is there a way to get the defered type of a class template parameter ? template <class TPtr> struct foo { typedef TPtr ptr_type; typedef ??? element_type; /* shall be the type of a deferred TPtr*/ }; so foo<const char*>::element_type results in const char, and foo<std::vector<int>::iterator_type>::element_type results in int. i am aware of that i can use the value_type typedef for c++ iterators (like std::vector<int>::iterator_type::value_type), but raw pointers havent got a value_type typedef, so i am out of luck there.

    Read the article

  • Fundamental types

    - by smerlin
    I always thought the following types are "fundamental types", so i thought my anwser to this question would be correct, but surprisingly it got downvoted... Searching the web, i found this. So, IBM says aswell those types are fundamental types.. Well how do you interpret the Standard, are following types (and similar types), "fundamental types" according to the c++ standard ? unsigned int signed char long double long long long long int unsigned long long int

    Read the article

  • Why do C# containers and GUI classes use int and not uint for size related members ?

    - by smerlin
    I usually program in C++, but for school i have to do a project in C#. So i went ahead and coded like i was used to in C++, but was surprised when the compiler complained about code like the following: const uint size = 10; ArrayList myarray = new ArrayList(size); //Arg 1: cannot convert from 'uint' to 'int Ok they expect int as argument type, but why ? I would feel much more comfortable with uint as argument type, because uint fits much better in this case. Why do they use int as argument type pretty much everywhere in the .NET library even if though for many cases negative numbers dont make any sense (since no container nor gui element can have a negative size). If the reason that they used int is, that they didnt expect that the average user cares about signedness, why didnt they add overloads for uint additonally ? Is this just MS not caring about sign correctness or are there cases where negative values make some sense/ carry some information (error code ????) for container/gui widget/... sizes ?

    Read the article

  • Visual Studio: Link executable

    - by smerlin
    Lets say I have: a static library project called "LIB" a application project called "LIBAPP" a application project called "APP" a application project called "APPTEST" When i add "LIB" to LIBAPP Project Dependencies, Visual Studio automatically links "LIBAPP" against LIB. But when i add APP to APPTEST Project Dependencies, it doesnt. Since i am doing unit tests of APP's classes in APPTEST, i have to link against APP, therefore i am currently manually linking against all *.obj files of APP (hundreds...) Since i have to change the link targets of APPTEST everytime i add or remove a *.cpp file from APP, this isnt a nice solution. So is there a way to force Visual Studio to do this for me automatically, like it does when adding a static library Project Dependency ?

    Read the article

  • question about c++ template functions taking any type as long that type meets at least one of the re

    - by smerlin
    Since i cant explain this very well, i will start with a small example right away: template <class T> void Print(const T& t){t.print1();} template <class T> void Print(const T& t){t.print2();} This does not compile: error C2995: 'void Print(const T &)' : function template has already been defined So, how can i create a template function which takes any type T as long as that type has a print1 memberfunction OR a print2 memberfunction (no polymorphism) ?

    Read the article

  • C# specifying generic delegate type param at runtime

    - by smerlin
    following setup, i have several generic functions, and i need to choose the type and the function identified by two strings at runtime. my first try looked like this: public static class FOOBAR { public delegate void MyDelegateType(int param); public static void foo<T>(int param){...} public static void bar<T>(int param){...} public static void someMethod(string methodstr, string typestr) { MyDelegateType mydel; Type mytype; switch(typestr) { case "int": mytype = typeof(int); break; case "double": mytype = typeof(double); break; default: throw new InvalidTypeException(typestr); } switch(methodstr) { case "foo": mydel = foo<mytype>; //error break; case "bar": mydel = bar<mytype>; //error break; default: throw new InvalidTypeException(methodstr); } for(int i=0; i<1000; ++i) mydel(i); } } since this didnt work, i nested those switchs (a methodstr switch inside the typestr switch or viceversa), but that solution is really ugly and unmaintainable. The number of types is pretty much fixed, but the number of functions like foo or bar will increase by high numbers, so i dont want nested switchs. So how can i make this working without using nested switchs ?

    Read the article

1