Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Syntax help with C++11: How would I call the constructor of std::function<stuff>  (Read 1047 times)

0 Members and 1 Guest are viewing this topic.

Critkeeper

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
if I am in the initializer list of the constructor of a class which inherits from std::function<stuff> ?

is it:

std::function< void ( Type argument, AnotherType anotherArgument )>() ?

So if I wanted to use the non-default constructor for std::function< stuff > I would do something like the following right?

Code: [Select]
Subclass::
Subclass( std::function< void ( Type argument, AnotherType anotherArgument )> happen )
    : std::function< void ( Type argument, AnotherType anotherArgument )>( happen )
{
    // stuff that needs to be initialized for this class
}



Code: [Select]
void functionImplementation( Type first, AnotherType second )
{
    // implementation of function
}


void (*functionPointer)( Type, AnotherType )
functionPointer = &functionImplementation;


Subclass action = new Subclass( functionPointer )


or I would use it like this with lambda:
Code: [Select]
Subclass
action =
new Subclass
(

    []
    ( Type firstArgument, AnotherType secondArgument)
    -> void
    {
        //implementation of function
    };
)


Does my constructor for Subclassneed to be changed in order to call the constructor for std::function< stuff > properly?
« Last Edit: March 02, 2015, 11:37:59 pm by Critkeeper »
if(CritKeeper.askQuestion()){return question.why();}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
This is the SFML forum. You'll get better answers in C++ dedicated communities.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything