Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Template class with variadic arguments

Template class with variadic arguments

Scheduled Pinned Locked Moved C / C++ / MFC
c++wpfcomhardwaretutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lxlxlx
    wrote on last edited by
    #1

    I have some troubles with generating a C++ template class. Goal is to add a function call with its arguments to a list for execution in a different task. The environment is a resource limited embedded system with a small task scheduler. I did some experiments, followed the An Idiot's Guide to C++ Templates but I’m not able to get this working:

    template
    class InstructionFunctionCall : public Instruction
    {
    private:
    // remember what to call... (with arguments)

    public:
    /// Execute instruction, called from a difrent task.
    virtual void execute (class Env *env)
    {
    // call the function with params.
    }

    SeBusInstructionFunctionCall(\_CallFunction Function, \_Args... Args)
    {
    	// store the call information.
    }
    

    };

    Could anybody give me a clue how I could template the storage of the variable arguments and use them in a function call? So I like to create an object with probably look someway like this:

    InstructionFunctionCall *function = new InstructionFunctionCall(SomeFunction, arg1, arg2);

    And later on where the call need to be executed:

    function->execute(); // executes: SomeFunction(arg1, arg2)

    Meanwhile I found this: Elegant Function Call Wrappers | Dr Dobb's article. It seems to be able do almost what I want, but it does not support a variable number of args.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups