Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
U

User 2601640

@User 2601640
About
Posts
12
Topics
5
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • safe-cast serialization
    U User 2601640

    If the answer is "It's impossible" that's fine. That's why I'm asking, because I don't know if a solution exists that satisfies my parameters.

    C / C++ / MFC

  • safe-cast serialization
    U User 2601640

    c-style cast is dangerous and hard to find in code. reinterpret_cast is not portable and just as dangerous as c-style. i want a typed way to serialize/deserialize.

    C / C++ / MFC

  • safe-cast serialization
    U User 2601640

    Thanks for the info. I'll take a look at the Boost serialization code to see how it is written.

    C / C++ / MFC

  • safe-cast serialization
    U User 2601640

    Is there a way in C++ to serialize objects into a char buffer without using reinterpret_cast or c-style casting (and backwards on the other end)? I also don't want to use C++ streams. I don't care how difficult it is. Thanks

    C / C++ / MFC

  • Distributed computing and multithreaded primers
    U User 2601640

    Can someone please recommend me good resources on distributed computing and multithreaded programming that will get me started quickly but not be too brief in their usefulness...oh and doesn't cost an arm and a leg? Nothing really jumped out at me on Amazon.com. All the books I noticed were either $100+, written in the 90's or not rated. Thanks

    .NET (Core and Framework) com question

  • Template parameter interpreted as base, not derived
    U User 2601640

    Thanks. I just posted a similar result based on the previous response. I appreciate the help.:thumbsup:

    C / C++ / MFC question

  • Template parameter interpreted as base, not derived
    U User 2601640

    Thanks for the response. Your output is what I expected. I was looking at the pointer types in the debugger, not printing out the type info to the console. The print statements give me what you got. I am using VS2008 v9 SP1. I was performing the wrong check to get a type match. I changed the function to the following:

    template<class T> bool CheckType(boost::shared_ptr<Base> pBase)
    {
    Base* pBaseRaw = pBase.get();
    if(pBaseRaw == null)
    {
    return false;
    }

    if(typeid(\*pBaseRaw) == typeid(T)) //Now dereferencing pBaseRaw. Bad idea?
    {
    	return true;
    }
    
    return false;
    

    }

    I am now dereferencing the base class pointer returned from shared_ptr which casts it to the right type. I believe this is a sketchy implicit cast to the derived type. Should I just dynamic_cast or does the typeid comparison take care of type issues? Thanks:thumbsup:

    C / C++ / MFC question

  • Template parameter interpreted as base, not derived
    U User 2601640

    I have a template function to check the type passed to it. I am templatizing it on a derived type but when I break in the function, the template parameter is the base class. A sample app is below. Can someone please explain where I am going wrong? Thanks

    class Base
    {
    public:
    virtual ~Base() {}
    };

    class Derived1 : public Base {};

    class Derived2 : public Base {};

    template<class T> bool CheckType(boost::shared_ptr<Base> pBase)
    {
    T* pTemplate = NULL; //Why is pTemplate Base* and not Derived1* when passing a Derived1 to template parameter?
    Base* pBaseRaw = pBase.get();
    if(typeid(pBaseRaw) == typeid(pTemplate))
    {
    return true;
    }

    return false;
    

    }

    int _tmain(int argc, _TCHAR* argv[])
    {
    boost::shared_ptr<Base> pBase1(new Derived1);
    boost::shared_ptr<Base> pBase2(new Derived2);
    bool bIsDerived = CheckType<Derived1>(pBase1);
    bIsDerived = CheckType<Derived2>(pBase2);

    return 0;
    

    }

    C / C++ / MFC question

  • How to handle smart ptrs and multiple inheritance?
    U User 2601640

    Thanks a bunch. That works great!

    C / C++ / MFC question oop tutorial

  • How to handle smart ptrs and multiple inheritance?
    U User 2601640

    Thanks for the response. Unfortunately, I was not clear enough in my question. The original shared_ptr is a pointer to one of the base classes. Here is an example:

    shared_ptr<Base1> pBase1(new Derived);
    Derived* pDerived = dynamic_cast<Derived*>(pBase1.get());
    shared_ptr<Base2> pBase2(pDerived);

    This code will crash but I want to accomplish the spirit of the code: 1) Create an object. 2) Somewhere in client code, have safe access to the object in terms of a pointer to one base class. 3) Somewhere else in client code, have safe access to the object in terms of a pointer to another base class. This appears to be more of a design question than a pointer/multiple inheritance use question. Thanks

    C / C++ / MFC question oop tutorial

  • How to handle smart ptrs and multiple inheritance?
    U User 2601640

    I have a class that implements two interfaces, IA and IB. Some portions of the code manipulate objects through IA pointers and other parts of the code manipulate objects through IB pointers. I would like those IA and IB clients to hold shared_ptr(ia) and shared_ptr(ib) instead of raw pointers. However, the ref count of one of the pointers could reach 0 before the other, delete the object and make the other pointer invalid. How do I practice safe use of smart ptrs of different interfaces to the same object? Thanks

    C / C++ / MFC question oop tutorial

  • Sutter/Alexandrescu explanation of Exceptions
    U User 2601640

    Sutter and Alexandrescu have a section on proper use of C++ exceptions that strongly encourages the use of C++ exceptions. I am confused by the last item, number 75, where they suggest avoiding exception specifications. 1) If you do not throw, then why bother trying to catch, which is what the previous items advocate? 2) If exception specifications are bad why does C++ support them? Can someone please explain what I am missing? Thanks

    C / C++ / MFC question c++
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups