mardi 24 novembre 2015

std::bind header file declaration

I want to create a std::bind for a function in a cpp file other than my main one, and also in a different namespace. The problem I'm having is how to declare said function in the header file since the binding itself depends on a variable not available to main.cpp.

It is something like this:

function.cpp

#include "function.h"
namespace A{
    void function(int i) { ... }   // supposed to be invisible from outside
    namespace A1{
        int varA1;
        auto func = std::bind(A::function, varA1);
    }
    namespace A2{
        int varA2;
        auto func = std::bind(A::function, varA2);
    }
}

function.h

namespace A{
    namespace A1{
        auto func();
    }
    namespace A1{
        auto func();
    }
}

I'm aware the above example does not work, but how do I change the header file in order to fix it?

Aucun commentaire:

Enregistrer un commentaire