Results 1 to 3 of 3

Thread: Polymorphism?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I want a class that I can use inside another class, but I want it to be a combination of 2 different classes. both would have the same functions but somewhere in the constructor I'd like to specify which one the class is using.
    say my 2 classes are

    Code:
    class A
    {
    
    public:
    
        A(void);
        long Fn(void);
    
    };
    
    A::A(void)
    {
    }
    
    long A::Fn(void)
    {
    
         return 10;
    
    }
    
    class B
    {
    
    long m_value;
    
    public:
    
        B(long Value);
        long Fn(void);
    
    };
    
    B::B(long Value)
    {
    m_value = Value;
    }
    
    long B::Fn(void)
    {
    
         return m_value;
    
    }
    Now say I want a class C with an overloaded contructor, if I don't include a value in the constructor it inherits a class A, if I do it inherits a class B.

    Is that possible?

  2. #2
    Guest
    How about defining two different constructors and depending on which one you use, you can create an instance of the class that is appropriate.
    Something like
    class C
    {
    public:
    C(void)
    {
    A a;
    }
    C(int in)
    {
    B a;
    }
    };

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Right, I was Kinda Hoping on Inheriting them rather than passing all the properties through(I'm including oversimple examples here) oh well

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width