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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:55:52+00:00 2026-06-17T12:55:52+00:00

I’ve just started making libraries in Arduino. I’ve made a library named inSerialCmd. I

  • 0

I’ve just started making libraries in Arduino. I’ve made a library named inSerialCmd. I want to call a function named delegate() that is defined in the main program file, stackedcontrol.ino, after the inSerialCmd library is included.

When I try to compile, one error is thrown:

…\Arduino\libraries\inSerialCmd\inSerialCmd.cpp: In member function
‘void inSerialCmd::serialListen()’:
…\Arduino\libraries\inSerialCmd\inSerialCmd.cpp:32: error:
‘delegate’ has not been declared

After doing a bit of searching, it seemed that adding the scope resolution operator might do the trick. So I added the “::” before delegate(), now “::delegate()”, but the same error is thrown.

Now I’m stumped.

  • 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-17T12:55:53+00:00Added an answer on June 17, 2026 at 12:55 pm

    You cannot and should not directly call a function in a program from a library. Keep in mind a key aspect that makes a library into a library:

    A library does not depend on the specific application. A library can be fully compiled and packaged into the .a file without the existence of a program.

    So there is a one way dependency, a program depends on a library. This at first glance may seem to prevent you from achieving what you want. You can achieve the functionality you are asking about through what is sometimes referred to as a callback. The main program would provide to the library at runtime a pointer to the function to execute.

    // in program somwehere
    int myDelegate(int a, int b);
    
    // you set this to the library
    setDelegate( myDelegate );
    

    You see this in the arduino if you look at how interrupt handlers are installed. This same concept exists in many environments – event listeners, action adapters – all with the same goal of allowing a program to define the specific action that a library cannot know.

    The library would store and call the function via the function pointer. Here is a rough sketch of what this looks like:

    // in the main program
    int someAction(int t1, int t2) {
      return 1;
    }
    
    /* in library
    this is the delegate function pointer
    a function that takes two int's and returns an int */
    int (*fpAction)(int, int) = 0;   
    
    /* in library
    this is how an application registers its action */
    void setDelegate( int (*fp)(int,int) ) {
      fpAction = fp; 
    }
    
    /* in libary
    this is how the library can safely execute the action */
    int doAction(int t1, int t2) {
      int r;
      if( 0 != fpAction ) {
        r = (*fpAction)(t1,t2);
      }
      else {
        // some error or default action here
        r = 0;
      }
      return r;
    }
    
    /* in program
    The main program installs its delegate, likely in setup() */
    void setup () {
      ...      
      setDelegate(someAction);
      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace

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.