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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:23:34+00:00 2026-05-28T05:23:34+00:00

I have a class that is designed to dynamically load a .dll or .so

  • 0

I have a class that is designed to dynamically load a .dll or .so or equivalent. From there, it will return pointers to whatever function you’re trying to find. Unfortunately, I’ve come across two issues in my implementation.

  1. If I use the ‘dumb’ function returning void* as pointers to functions, I get warning: ISO C++ forbids casting between pointer-to-function and pointer-to-object when I try to manipulate them into a form I can use.
  2. If I try using the ‘smart’ function with variadic templates and type safety, I can’t get it to compile. error: no matching function for call to ‘Library::findFunction(std::string&)’ is the only thing that awaits me here. As you can see from the code below, this should match the function signature. Once it does compile, issue 1 will be present here too.

For reference, I am compiling under Ubuntu 10.10 x86_64 with g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5. I have also tried compiling with g++-4.5 (Ubuntu/Linaro 4.5.1-7ubuntu2) 4.5.1 however this does not change anything.

#include <string>
#include <stdio.h>

class Library
{
public:
    Library(const std::string& path) {}
    ~Library() {}

    void* findFunction(const std::string& funcName) const
    {
        // dlsym will return a void* as pointer-to-function here.
        return 0;
    }

    template<typename RetType, typename... T>
    RetType (*findFunction(const std::string& funcName))(T... Ts) const
    {
        return (RetType (*)(...))findFunction(funcName);
    }

};

int main()
{
    Library test("/usr/lib/libsqlite3.so");

    std::string name = "sqlite3_libversion";
    const char* (*whatwhat)() = test.findFunction<const char*, void>(name);
    // this SHOULD work. it's the right type now! >=[

    //const char* ver3 = whatwhat();
    //printf("blah says \"%s\"\n", ver3);
}
  • 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-28T05:23:34+00:00Added an answer on May 28, 2026 at 5:23 am

    I think you need to change the returned function signature to T... instead of just ... otherwise it expects a variable arglist even when it should just be empty.

    template<typename RetType, typename... T>
    RetType (*findFunction(const std::string& funcName))(T... Ts) const
    {
        return (RetType (*)(T...))findFunction(funcName);
    }
    

    Then call it without the void in the type list and it should work:

    const char* (*whatwhat)() = test.findFunction<const char*>(name);
    

    With these changes it compiles for me on gcc-4.5.1: http://ideone.com/UFbut

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

Sidebar

Related Questions

I have a class (class A) that is designed to be inherited by other
I have some C# class libraries, that were designed without taking into account things
I have a variation on a Quantity (Fowler) class that is designed to facilitate
I have designed the following class that should work kind of like a method
I have designed several animated Panel s in C# that all inherit from one
I have a class that is designed primarily as a POCO class, with various
I have a class which implements IHttpHandler that is designed to handle image resize
Sometimes you have a class that is designed to be inherited, but not all
While developing a game I have designed a class that in normal operation has
I have created a class, Metrics that is designed to be subclassed to customize

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.