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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:39:34+00:00 2026-06-05T12:39:34+00:00

In the following exceedingly abbreviated classes I would like to define in the base

  • 0

In the following exceedingly abbreviated classes I would like to define in the base a method (ProcessLines) that would iterate over a set of database records, passing each record as a parameter to a function that is only defined in the child class. Obviously the Base is a virtual class that will never be instantiated on its own.

Class Base {
 public:
  typedef ProcLineFunc( Long *Line );
  void ProcessLines( ProcLineFunc pf);
}

Class Child{
  void DoWork( Long *Line) { //do something}
}

I’m not sure how to implement this. If I redeclare ProcessLines in the child and just call the parent method, I get the same error message as if I call ProcessLines in the code that creates the child.

Child c(//something);
c.ProcessLines(c.DoWork);

Gives me a compiler message:

[BCC32 Error] main.cpp(67): E2034 Cannot convert ‘bool (* (_closure )(long *))(long )’ >to ‘int ()(long *)’
Full parser context
main.cpp(56): class Add2Chan
main.cpp(78): decision to instantiate: bool Add2Chan::ProcessByLines()
— Resetting parser context for instantiation…
main.cpp(67): parsing: bool Add2Chan::ProcessByLines()

I’m fairly new to c++ and the E2034 error message scares the daylights out of me.

Please help. I used a typedef so that I can, in my child classes call ProcessLines multiple times, passing in different functions as I go.

  • 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-06-05T12:39:37+00:00Added an answer on June 5, 2026 at 12:39 pm

    Instead of using pointers to functions, use pointers to objects. Accept the limitation that your function is going to be called DoWork and nothing else, and there can only be one such function in each class. This is not a bad limitation. Declare the (pure virtual) function in a class (which is called an interface), and derive classes from it (they are said to implement an interface).

    struct DoingWork
    {
        virtual void DoWork(long *Line) = 0; // does some work on a list
    };
    
    struct DoingGreatWork: DoingWork
    {
        virtual void DoWork(long *Line) {printf("Great work\n");}
    };
    
    struct DoingSlightWork: DoingWork
    {
        virtual void DoWork(long *Line) {printf("Slight work\n");}
    };
    

    Using this example:

    class Base {
      public:
        void ProcessLines(DoingWork& object) {
            //Logic to process lines here
            while(moreLines) {
                object.DoWork(line);
            }
        }
    };
    
    class Whatever // no need to derive from Base
    {
        void DoStuff()
        {
            Base object;
    
            object.ProcessLines(DoingGreatWork());
            object.ProcessLines(DoingSlightWork());
        }
    }
    

    If the working objects have to have access to the calling object, initialize them like this:

    class Whatever // no need to derive from Base
    {
        struct DoingElaborateWork: DoingWork
        {
            Whatever& caller;
            DoingElaborateWork(Whatever& caller): caller(caller) {}
            virtual void DoWork(long *Line)
            {
                printf("Doing work requested by %s\n", caller.name());
            }
        };
    
        void DoStuff()
        {
            Base object;
            object.ProcessLines(DoingElaborateWork(*this));
        }
    
        const char* name() {return "Whatever";}
    }
    

    P.S. They say that “in C++03 functions are second-class citizens” because you cannot do with functions what you can do with objects (like this solution i provide). I heard that in C++11 functions are much improved, but i am not sure about the details.

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

Sidebar

Related Questions

Following method is accepted if I set UIColor like: [tabBarController.tabBar setSelectedImageTintColor:[UIColor greenColor]]; However I
Following is the association between 2 models: class FotoGossip < ActiveRecord::Base has_many :uploads end
Following Uncle Bob's avice in Clean Code , I'd like to have no SQL
Following is the stack trace. I read that the Broken Pipe is because of
Following String causes PatternSyntaxException : Pattern.compile(*\\.*); I want to create a pattern so that
Following this JavaFX 2.0 tutorial I created a css file in eclipse that includes
Following the instructions here: http://www.padrinorb.com/guides/padrino-mailer I have the delivery method added on the app.rb
I'm working with a tabbed interface and have the following jQuery function set up
I have a database where I store objects. I have the following (simplified) schema
I have the following code which works well, but the problem is that after

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.