Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3598770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:17:02+00:00 2026-05-18T20:17:02+00:00

I have class with two fields witch are pointers to abstract class. How i

  • 0

I have class with two fields witch are pointers to abstract class. How i can write copy constructor witch will copy the data pointed with the two pointers.

Here is the class

class OSGFMenu;
class OSGFMenuItem;
typedef void(OSGFMenu::*OSGFMenuCommand)(OSGFMenuItem*);
typedef int (OSGFMenuItem::*FNMETHOD) ( int, char* );
class OSGFMenuItem:
    public OSGFDrawableComponent
{
public:
    OSGFMenuItem(Game& game,OSGFMenu& menu)
        :OSGFDrawableComponent(game),mMenu(menu),mActive(false)
    {
    }
    OSGFMenuItem(const OSGFMenuItem& menuItem)
        :OSGFDrawableComponent(menuItem),mMenu(menuItem.mMenu)
    {
        Copy(menuItem);
    }
    OSGFMenuItem& operator=(const OSGFMenuItem& menuItem)
    {
        if(&menuItem != this)
            Copy(menuItem);
        return *this;
    }
    void SetActive(bool active)
    {
        mActive = active;
    }
    void Activate()
    {
        SetActive(true);
    }
    void DeActivate()
    {
        SetActive(false);
    }
    void SetCommand(OSGFMenuCommand command)
    {
        mCommand = command;
    }
    virtual void Render()const
    {
        if(!mActive)
            DrawIfNotNull(mDrawData);
        else
            if(!DrawIfNotNull(mActiveDrawData))
                DrawIfNotNull(mDrawData);

    }
    virtual void Update(double dTime)
    {
        OSGFDrawableComponent* drawData = 
            dynamic_cast<OSGFDrawableComponent*>(mDrawData);
        if(drawData)
            drawData->Update(dTime);
    }
    void Invoke()
    {
        (mMenu.*mCommand)(this);
    }
    ~OSGFMenuItem()
    {
        SafeDelete(mDrawData);
        SafeDelete(mActiveDrawData);
    }
protected:
    void SetDrawData(IDrawable* drawData)
    {
        mDrawData = drawData;
    }
    void SetActiveDrawData(IDrawable* drawData)
    {
        mActiveDrawData = drawData;
    }
private:
    bool DrawIfNotNull(IDrawable* drawData)const
    {
        if(!drawData)return false;
        drawData->Render();
        return true;
    }
    void Copy(const OSGFMenuItem& menuItem)
    {
        mCommand = menuItem.mCommand;
        *mDrawData = *menuItem.mDrawData;
        *mActiveDrawData = *menuItem.mActiveDrawData;
        mActive = menuItem.mActive;
    }
    OSGFMenuCommand mCommand;
    OSGFMenu& mMenu;
    IDrawable* mDrawData;
    IDrawable* mActiveDrawData;
    bool mActive;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:17:02+00:00Added an answer on May 18, 2026 at 8:17 pm

    If you need to copy the exact type of the IDrawable hierarchy, I think your only chance is to add a Clone() abstract method to IDrawable interface.

    Its signature will be

    IDrawable* clone() const;

    you may omit const if it needs to modify the object pointed by this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class with two fields witch are pointers to abstract class. How i
I have a persistent class Author with two fields: int id , String name
I have an example class containing two data points: public enum Sort { First,
I have a class A containing two pointers to objects of another class B.
I have a class with two date fields say: class TestData { Date activation;
I have a very simple class with two fields, String sourceAddress and int port.
I have two fields of an entity class which I don't want to be
I have simple class Point with two fields of type double . I asked
I have two input fields fromDate and toDate which are instances of Date class.
I have a class with two methods defined in it. public class Routines {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.