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

  • Home
  • SEARCH
  • 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 4267448
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:54:03+00:00 2026-05-21T06:54:03+00:00

I think they are called functors? (it’s been a while) Basically, I want to

  • 0

I think they are called functors? (it’s been a while)

Basically, I want to store a pointer to a function in a variable, so I can specify what function I want to use from the command line.

all the functions return and take the same values.

unsigned int func_1 (unsigned int var1)
unsigned int func_2 (unsigned int var1)

function_pointer = either of the above?

so then I could call it by going: function_pointer(my_variable)?

EDIT:
as per @larsmans’s suggestion, I’ve gotten this:
Config.h:

class Config
{
public:
    unsigned static int (*current_hash_function)(unsigned int);
};

Config.cpp:

#include "Config.h"
#include "hashes.h"
unsigned static int (*current_hash_function)(unsigned int) = kennys_hash_16;

hashes.h:

unsigned int kennys_hash(unsigned int out);
unsigned int kennys_hash_16(unsigned int out);

hashes.cpp:

just implements the functions in the header

main.cpp:

#include "Config.h"
#include "hashes.h"
// in test_network:
    unsigned int hashed = Config::current_hash_function(output_binary);

//in main():
        else if (strcmp(argv[i], "-kennys_hash_16") == 0)
        {
            Config::current_hash_function = kennys_hash_16;
        }
        else if (strcmp(argv[i], "-kennys_hash_8") == 0)
        {
            Config::current_hash_function = kennys_hash;
        }

the error I get:

g++ -o hPif src/main.o src/fann_utils.o src/hashes.o src/Config.o -lfann -L/usr/local/lib 
Undefined symbols:
  "Config::current_hash_function", referenced from:
      test_network()     in main.o // the place in the code I've selected to show
      auto_test_network_with_random_data(unsigned int, unsigned int, unsigned int)in main.o
      generate_data(unsigned int, unsigned int, unsigned int)in main.o
      _main in main.o // the place in the code I've selected to show
      _main in main.o // the place in the code I've selected to show
      generate_train_file()     in fann_utils.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [hPif] Error 1
  • 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-21T06:54:04+00:00Added an answer on May 21, 2026 at 6:54 am

    The simplest you can do is

    unsigned int (*pFunc)(unsigned int) = func_1;
    

    This is a bare function pointer, which cannot be used to point to anything other than a free function.

    You can make it less painful if your compiler supports the C++0x auto keyword:

    auto pFunc = func_1;
    

    In any case, you can call the function with

    unsigned int result = pFunc(100);
    

    There are many other options that provide generality, for example:

    • You can use boost::function with any C++ compiler
    • With a compiler implementing features of C++0x you can use std::function

    These can be used to point to any entity that can be invoked with the appropriate signature (it’s actually objects that implement an operator() that are called functors).

    Update (to address updated question)

    Your immediate problem is that you attempt to use Config::current_hash_function (which you declare just fine) but fail to define it.

    This defines a global static pointer to a function, unrelated to anything in class Config:

    unsigned static int (*current_hash_function)(unsigned int) = kennys_hash_16;
    

    This is what you need instead:

    unsigned int (*Config::current_hash_function)(unsigned int) = kennys_hash_16;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At my previous job they used a product called Whole Tomato (I think that's
If you think they are not, please give an example for a string that
I have two tables called clients, they are exactly the same but within two
Upon discovering that SDL and X11 use the same keyboard key IDs (I think
I don't think my future lies in Android development, as I am consistently failing
New guy here so bear with me. Ive got a basic XSL file that
I have the following HTML on my page: <div id=mypanel> <span>SomeText</span> <span>SomeText2</span> <span>SomeText3</span> <span>SomeText4</span>
I'm trying to make sure that I don't leave any loose ends open in
I'm a member of a small but fairly sociable online forum, and just for
I am about to start a pilot project in our company to introduce agile

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.