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 3806490
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:50:38+00:00 2026-05-19T14:50:38+00:00

So in structure like struct RenderCastedDataFunctor { simpleRendererGraphElement* obj_; RenderCastedDataFunctor(simpleRendererGraphElement* obj) : obj_(obj) {

  • 0

So in structure like

struct RenderCastedDataFunctor
{
    simpleRendererGraphElement* obj_;

    RenderCastedDataFunctor(simpleRendererGraphElement* obj)
        : obj_(obj) { }

    void operator()(char* castedChar, int castedCharLength)
    {
        obj_->renderCastedData(castedChar, castedCharLength);
    }
};

can we turn simpleRendererGraphElement* into abstract type and make its function name we use in structure (renderCastedData) abstract too?

So I have a function inside charGenerator class

template <typename Function>
void AddSubscriberToGeneratedData(Function f)

I want to pass to it functions from different classes of type void (differentClass::*)(char*, int)

With that structure inside some simpleRendererGraphElement I can subscribe function called renderCastedData to data with
charGenerator->AddSubscriberToGeneratedData(RenderCastedDataFunctor(this));
I want to have a way to be capable to pass abstract class function that takes char* and int to AddSubscriberToGeneratedData. How to do such thing?

  • 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-19T14:50:38+00:00Added an answer on May 19, 2026 at 2:50 pm

    can we turn
    simpleRendererGraphElement* into
    abstract type and make its function
    name we use in structure
    (renderCastedData) abstract too?

    Very very good idea. You should do this. Make the class abstract by making it’s functions virtual, and then define a concrete class (deriving from this abstract class) which implements the virtual functions. That would be a better design!

    And the rest seems already fine. You don’t have to do anything, as you’re doing this:

    AddSubscriberToGeneratedData(RenderCastedDataFunctor(this));
    

    I suppose, here this represents the pointer to an instance of the concrete class. If so, then that should work!


    EDIT:

    I understand how good this Idea is but
    I do not get how to implement it. that
    is why I am asking.

    Alright. Here is an example:

    class AbstractGraphElement
    {
      public:
        virtual void RenderCastedData(char* castedChar, int castedCharLength) = 0;
    };
    

    This is your abstract class, and RenderCastedData is a pure virtual function. Now you need to define a concrete class which must define RenderCastedData function. So here it is:

    class SimpleGraphElement : public AbstractGraphElement
    {
      public:
        virtual void RenderCastedData(char* castedChar, int castedCharLength)
        {
            //function body - define it yourself
        }
    };
    

    Done!

    Now what you need to do is this. Modify RenderCastedDataFunctor as follows:

    struct RenderCastedDataFunctor
    {
        AbstractGraphElement* m_graphElement;
    
        RenderCastedDataFunctor(AbstractGraphElement* graphElement)
            : m_graphElement(graphElement) { }
    
        void operator()(char* castedChar, int castedCharLength)
        {
            m_graphElement->RenderCastedData(castedChar, castedCharLength);
        }
    };
    

    Then add subscriber,

    AbstractGraphElement *pGraphElement = new SimpleGraphElement();
    AddSubscriberToGeneratedData(RenderCastedDataFunctor(pGraphElement));
    

    I think it gave your some idea, right? The important point is : use pointer of type AbstractGraphElement but initialize this pointer with SimpleGraphElement. I think, you should read about virtual functions, and runtime polymorphism. That would help you a lot.

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

Sidebar

Related Questions

I have a structure like struct board{ char name; int values[37]; }board Imagine a
Let's say I have a first structure like this: typedef struct { int ivalue;
Which is a more efficient. A Trie structure like this: struct TrieNode { char
I have a structure defined like so: typedef struct { int n; int *n_p;
I have a List of an Record(structure) like this : struct Rec { int
I have a structure like struct category { int id,newID; std::string name; }; and
I have a data structure like this: struct foo { int id; int route;
I have program, that has structure defined like this: struct foo { int magic;
Having a structure like this in C++11: struct von { std::string Name; unsigned int
I have a structure like this. struct A { int someFun() const; int _value;

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.