Thread: copy constructor for a class with an abstract member

  1. #1
    Registered User
    Join Date
    Dec 2015
    Posts
    13

    copy constructor for a class with an abstract member

    Hi everyone!


    This question is related to how implement a copy constructor for a class that has a pointer to an abstract type. Here is an example:


    Code:
    class MyAbstract
    {
    public:    
        virtual void abstractMethod() const = 0;
    
    
    };
    
    
    class UseAbstract
    {
    public:
        UseAbstract (MyAbstract *abstract, int b)
        {
            abstract_ = abstract;
            b_ = b;
        }
        
        UseAbstract (const UseAbstract &other)
        {
            b_ = other.b_;
            //abstract_ = new ??
        }
        
    private:
        MyAbstract *abstract_;
        int b_;
    };



    How can I implement the copy constructor for UseAbstract? I can't create an object for 'MyAbstract'.


    Thanks a lot!

  2. #2
    Registered User
    Join Date
    Jun 2017
    Posts
    156
    Same topic as copy constructor for a class with an abs - C++ Forum
    maybe the solutions works for you as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-22-2012, 01:11 PM
  2. Replies: 3
    Last Post: 12-31-2011, 02:23 AM
  3. Replies: 51
    Last Post: 02-09-2009, 05:35 PM
  4. abstract class member cannot be overladed?
    By dudeomanodude in forum C++ Programming
    Replies: 10
    Last Post: 12-10-2008, 11:12 AM
  5. Replies: 9
    Last Post: 06-20-2008, 02:41 AM

Tags for this Thread