Thread: Multiple inheritance: casting yields different address

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by dwks
    The ReferenceCounter is using const void* pointers and uses typeid to remember the type of the original object added to it. I don't really think it can be improved that much, unless there's a way to detect whether a class is multiply-inherited or not.
    Why didn't you go for say, std::tr1::shared_ptr instead of ReferenceCounter?

    Quote Originally Posted by dwks
    Maybe I've been using too much Java lately, because it would be a perfect place to use Java interfaces.
    A class without data members defines a pure interface, so the C++ near-equivalent to a Java interface is an abstract base class without data members. That said, I think you knew this already

    EDIT:
    Oh, looking at your code again, maybe the appropriate solution in this case is to use virtual inheritance:
    Code:
    class Branch1 : virtual public Base {};
    class Branch2 : virtual public Base {};
    Last edited by laserlight; 06-05-2009 at 10:26 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to Send Mac Address From Client to Server
    By Lieyza197 in forum C Programming
    Replies: 2
    Last Post: 05-27-2009, 09:58 AM
  2. Multiple Inheritance Question
    By ss3x in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2002, 06:09 AM
  3. Multiple Inheritance Ambiguity
    By FillYourBrain in forum C++ Programming
    Replies: 21
    Last Post: 08-23-2002, 10:31 AM
  4. C++ multiple inheritance problem
    By pongsor in forum C++ Programming
    Replies: 7
    Last Post: 02-08-2002, 08:18 PM
  5. Multiple virtual inheritance
    By kitten in forum C++ Programming
    Replies: 3
    Last Post: 08-10-2001, 10:04 PM