SFML community forums

Help => General => Topic started by: Critkeeper on March 02, 2015, 11:15:22 pm

Title: Syntax help with C++11: How would I call the constructor of std::function<stuff>
Post by: Critkeeper on March 02, 2015, 11:15:22 pm
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?
Title: AW: Syntax help with C++11: How would I call the constructor of std::function<stuff>
Post by: eXpl0it3r on March 02, 2015, 11:19:56 pm
This is the SFML forum. You'll get better answers in C++ dedicated communities.